我有由 rush ( https://rushjs.io/) 管理的单一存储库
代码结构为:
如您所见,有两个 eslint 配置和两个目录 node_modules
(它只是 rush 创建的符号链接(symbolic link))。
Eslint 支持完美工作。
但是我在使用前面的 eslint 配置时遇到了一些麻烦。当我运行它时
yarn eslint --ext .js --ext .jsx ./src
来自目录 front
,它工作。
但是当 eslint 从 vscode 启动时,它不起作用。在输出中我看到:
Consider running eslint --debug /Users/oleg/Desktop/projects/hire/front/src/pages/config.js from a terminal to obtain a trace about the configuration files used.
[Error - 2:04:08 PM]
Failed to load plugin 'react' declared in 'front/.eslintrc': Cannot find module 'eslint-plugin-react'
Require stack:
- /Users/oleg/Desktop/projects/hire/__placeholder__.js
Referenced from: /Users/oleg/Desktop/projects/hire/front/.eslintrc
Happened while validating /Users/oleg/Desktop/projects/hire/front/src/pages/config.js
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.
eslint-plugin-react
已经安装并定义在 front/package.json
你知道为什么 eslint 不能工作吗?
P.S Eslint 配置:
{
"parser": "babel-eslint",
"extends": [
"airbnb",
"plugin:react/recommended"
],
"env": {
"browser": true,
"node": true,
"jest": true,
"es6": true
},
"plugins": [
"react",
"jsx-a11y"
],
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"newline-before-return": "error",
"newline-after-var": "error",
"arrow-parens": [
"error",
"always"
],
"arrow-body-style": [
2,
"as-needed"
],
"comma-dangle": [
2,
"always-multiline"
],
"import/imports-first": 0,
"import/newline-after-import": 0,
"import/no-extraneous-dependencies": 0,
"import/no-named-as-default": 0,
"import/no-unresolved": 2,
"import/prefer-default-export": 0,
"indent": [
2,
2,
{
"SwitchCase": 1
}
],
"max-len": 0,
"newline-per-chained-call": 0,
"no-confusing-arrow": 0,
"no-console": 1,
"no-use-before-define": 0,
"prefer-template": 2,
"class-methods-use-this": 0,
"react/forbid-prop-types": 0,
"react/jsx-first-prop-new-line": [
2,
"multiline"
],
"react/jsx-no-target-blank": 0,
"react/require-extension": 0,
"react/self-closing-comp": 0,
"react/display-name": 0,
"require-yield": 0,
"import/no-webpack-loader-syntax": 0,
"react/prop-types": [
0
]
},
"settings": {
"babel-plugin-root-import": {
"rootPathPrefix": "~/",
"rootPathSuffix": "src/"
},
"import/resolver": {
"webpack": {
"config": "./webpack/webpack.prod.js"
}
}
},
"globals": {
"CONFIG": true
}
}
最佳答案
添加到工作区设置:
{
"eslint.workingDirectories": [
"back",
"front"
]
}
并且可能:
{
"eslint.workingDirectories": [
{
"directory": "front",
"changeProcessCWD": true
}
]
}
问题在于 vscode/eslint 在哪里寻找依赖项。
关于javascript - Eslint 在 VScode 中不工作,但在终端工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56988147/