[英]Atom & eslint: Cannot find module 'eslint-config-react-app'
Since I reinstalled my NPM dependencies in my create-react-app project, Atom's eslint gives me this error on the top of every file:由于我在我的 create-react-app 项目中重新安装了我的 NPM 依赖项,因此 Atom 的 eslint 在每个文件的顶部都给了我这个错误:
Error while running ESLint: Cannot find module 'eslint-config-react-app'.
While react-scripts
's eslint doesn't raise any warning or error.虽然react-scripts
的 eslint 不会引发任何警告或错误。 By the way, the package eslint-config-react-app
is installed in node_modules
.顺便说一句,package eslint-config-react-app
安装在node_modules
中。 I tried to reinstall linter-eslint, atom, the NPM dependencies, etc. Nothing worked.我尝试重新安装 linter-eslint、atom、NPM 依赖项等。没有任何效果。
Has anyone an idea?有人有想法吗?
Here is my.eslintrc:这是我的.eslintrc:
{
"extends": "react-app",
"rules": {
"jsx-a11y/anchor-is-valid": 0,
"react/jsx-no-comment-textnodes": 0,
"no-unused-vars": ["warn", {
args: "all",
ignoreRestSiblings: false,
argsIgnorePattern: "^_$"
}]
}
}
Edit: I don't know why, but all of the sudden, the error changed and now it's this one on top of every js file:编辑:我不知道为什么,但突然之间,错误发生了变化,现在它是每个 js 文件顶部的错误:
Error while running ESLint: Invalid regular expression flags
EDIT 2编辑 2
None of the given solutions worked in my case.给定的解决方案都不适用于我的情况。 The problem with linter-eslint
is not solved. linter-eslint
的问题没有解决。 But I found a workaround for now: using fast-eslint
instead of linter-eslint
.但我现在找到了一种解决方法:使用fast-eslint
而不是linter-eslint
。 Works just fine.工作得很好。
For anyone else trying this, one solution is installing eslint-config-react-app globally, along with all of its peer deps.对于尝试此操作的其他人,一种解决方案是全局安装 eslint-config-react-app 及其所有对等部门。 At the moment, that's:此刻,就是:
Refer to https://github.com/facebook/create-react-app/issues/3633#issuecomment-361485857参考https://github.com/facebook/create-react-app/issues/3633#issuecomment-361485857
npm i -g babel-eslint@^7.2.3 eslint@^4.1.1 eslint-plugin-flowtype@^2.34.1 eslint-plugin-import@^2.6.0 eslint-plugin-jsx-a11y@^5.1.1 eslint-plugin-react@^7.1.0
Since you mentioned that the problem occurred after you reinstalled npm modules, it might be related to npm dependency resolution.由于您提到问题是在您重新安装 npm 模块后出现的,它可能与 npm 依赖解析有关。 So you might have multiple versions of the same module and atom might use the wrong one.因此,您可能有同一个模块的多个版本,而 atom 可能会使用错误的版本。
Check whether your react-scripts version is 0.2.0 or higher according to Displaying Lint Output in the Editor根据Displaying Lint Output in the Editor检查您的 react-scripts 版本是否为 0.2.0 或更高
Remove all eslint
related dependencies from your package.json
.从 package.json 中删除所有与eslint
相关的依赖package.json
。
This means removing babel-eslint
, eslint
, eslint-plugin-flowtype
, eslint-plugin-import
, eslint-plugin-jsx-a11y
, eslint-plugin-react
, etc这意味着删除babel-eslint
、 eslint
、 eslint-plugin-flowtype
、 eslint-plugin-import
、 eslint-plugin-jsx-a11y
、 eslint-plugin-react
等
Create react app installs all the linting dependencies under the hood so you shouldn't manually install them. Create react app 会在后台安装所有 linting 依赖项,因此您不应手动安装它们。
Remove all global eslint
related dependencies.删除所有与全局eslint
相关的依赖项。
Generally you don't need to use globally installed eslint dependencies as you might have different eslint versions in each of your projects.通常,您不需要使用全局安装的 eslint 依赖项,因为您的每个项目中可能有不同的 eslint 版本。
The latest version of linter-eslint should then use the correct eslint dependencies from under node_modules
in your project.然后,最新版本的linter-eslint应该使用项目中 node_modules 下的正确node_modules
依赖项。
UPDATE : Based on your comments and edited question, I tried reproducing this using CRA, replacing the dependencies in package.json
, reinstalling and adding the following .eslintrc
.更新:根据您的评论和编辑的问题,我尝试使用 CRA 重现此内容,替换package.json
中的依赖项,重新安装并添加以下.eslintrc
。
Notice I added "
around the options keys in the "no-unused-vars"
.请注意,我在"no-unused-vars"
"
{
"extends": "react-app",
"rules": {
"jsx-a11y/anchor-is-valid": 0,
"react/jsx-no-comment-textnodes": 0,
"no-unused-vars": ["warn", {
"args": "all",
"ignoreRestSiblings": false,
"argsIgnorePattern": "^_$"
}]
}
}
Having done all this I couldn't reproduce the issue.完成所有这些后,我无法重现该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.