在通过 Yarn 管理的 VSCode 中使用自定义 eslint 配置文件
Posted
技术标签:
【中文标题】在通过 Yarn 管理的 VSCode 中使用自定义 eslint 配置文件【英文标题】:Use custom eslint config file in VSCode that is managed via Yarn 【发布时间】:2018-08-20 23:44:20 【问题描述】:我已经在 VSCode 中安装并运行了 eslint,但它没有使用我们的配置文件。
我更改的设置是
"eslint.nodePath": "C:\\Users\\PARAGON\\Documents\\AllCode\\ParagonCore\\clients\\utilities\\paragon-scripts\\node_modules",
"eslint.options":
"configFile": "C:\\Users\\PARAGON\\Documents\\AllCode\\ParagonCore\\clients\\utilities\\paragon-scripts\\configuration\\.eslintrc.js",
,
"eslint.packageManager": "yarn",
更新:
修改nodePath并修复文件路径错误
[Info - 12:30:26 PM] ESLint library loaded from:
C:\Users\PARAGON\AppData\Local\Yarn\config\global\node_modules\eslint\lib\api.js
[Error - 12:30:26 PM] Cannot read config file: C:\Users\PARAGON\Documents\AllCode\Paragon\ParagonCore\clients\utilities\paragon-scripts\configuration\.eslintrc.js Error: Cannot find module 'C:\Users\PARAGON\Documents\AllCode\Paragon\ParagonCore\clients\utilities\paragon-scripts\configuration\.eslintrc.js'
[Error - 12:32:56 PM]
Failed to load plugin react: Cannot find module 'eslint-plugin-react'
Happened while validating C:\Users\PARAGON\Documents\AllCode\ParagonCore\clients\job-grid\source\scripts\components\AssignToUser.jsx
This can happen for a couple of reasons:
1. The plugin name is spelled incorrectly in an ESLint configuration file (e.g. .eslintrc).
2. If ESLint is installed globally, then make sure 'eslint-plugin-react' is installed globally as well.
3. If ESLint is installed locally, then 'eslint-plugin-react' isn't installed correctly.
Consider running eslint --debug C:\Users\PARAGON\Documents\AllCode\ParagonCore\clients\job-grid\source\scripts\components\AssignToUser.jsx from a terminal to obtain a
trace about the configuration files used.
Failed to load plugin react: Cannot find module 'eslint-plugin-react'
Happened while validating C:\Users\PARAGON\Documents\AllCode\ParagonCore\clients\job-grid\source\scripts\components\controls\CreateJob.jsx
This can happen for a couple of reasons:
1. The plugin name is spelled incorrectly in an ESLint configuration file
(e.g. .eslintrc).
2. If ESLint is installed globally, then make sure 'eslint-plugin-react' is
installed globally as well.
3. If ESLint is installed locally, then 'eslint-plugin-react' isn't installed correctly.
Consider running eslint --debug
C:\Users\PARAGON\Documents\AllCode\ParagonCore\clients\job-
grid\source\scripts\components\controls\CreateJob.jsx from a terminal to
obtain a trace about the configuration files used.
【问题讨论】:
查找 eslint 配置文件应该与您使用的包管理器无关。您是否在与配置文件夹处于同一级别的文件夹中打开 VSCode?span> @NathanBierema 打开的文件夹是 3 级 听起来像是在解析 eslint 模块,而不是配置文件。如果您使用"eslint.packageManager": "yarn"
选项,请确保使用 Yarn 全局安装 eslint。
你也必须全局安装 eslint-plugin-react
看起来像。
【参考方案1】:
首先,确保您没有全局安装该软件包。然后,将"eslint.nodePath"
设置为与配置目录平行的node_modules
目录位置。
yarn global remove eslint
"eslint.nodePath": "C:/.../node_modules"
打开一些文件并在“输出”窗口中查找“ESLint library loaded from:”
【讨论】:
以上是关于在通过 Yarn 管理的 VSCode 中使用自定义 eslint 配置文件的主要内容,如果未能解决你的问题,请参考以下文章
是否可以将 yarn-pnp 与 typescript/vscode 一起使用?