![](/img/trans.png)
[英](ESLint) Cannot find module 'eslint-config-react-app' in VS 2017 react project
[英]Atom & eslint: Cannot find module 'eslint-config-react-app'
由於我在我的 create-react-app 項目中重新安裝了我的 NPM 依賴項,因此 Atom 的 eslint 在每個文件的頂部都給了我這個錯誤:
Error while running ESLint: Cannot find module 'eslint-config-react-app'.
雖然react-scripts
的 eslint 不會引發任何警告或錯誤。 順便說一句,package eslint-config-react-app
安裝在node_modules
中。 我嘗試重新安裝 linter-eslint、atom、NPM 依賴項等。沒有任何效果。
有人有想法嗎?
這是我的.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: "^_$"
}]
}
}
編輯:我不知道為什么,但突然之間,錯誤發生了變化,現在它是每個 js 文件頂部的錯誤:
Error while running ESLint: Invalid regular expression flags
編輯 2
給定的解決方案都不適用於我的情況。 linter-eslint
的問題沒有解決。 但我現在找到了一種解決方法:使用fast-eslint
而不是linter-eslint
。 工作得很好。
對於嘗試此操作的其他人,一種解決方案是全局安裝 eslint-config-react-app 及其所有對等部門。 此刻,就是:
參考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
由於您提到問題是在您重新安裝 npm 模塊后出現的,它可能與 npm 依賴解析有關。 因此,您可能有同一個模塊的多個版本,而 atom 可能會使用錯誤的版本。
根據Displaying Lint Output in the Editor檢查您的 react-scripts 版本是否為 0.2.0 或更高
從 package.json 中刪除所有與eslint
相關的依賴package.json
。
這意味着刪除babel-eslint
、 eslint
、 eslint-plugin-flowtype
、 eslint-plugin-import
、 eslint-plugin-jsx-a11y
、 eslint-plugin-react
等
Create react app 會在后台安裝所有 linting 依賴項,因此您不應手動安裝它們。
刪除所有與全局eslint
相關的依賴項。
通常,您不需要使用全局安裝的 eslint 依賴項,因為您的每個項目中可能有不同的 eslint 版本。
然后,最新版本的linter-eslint應該使用項目中 node_modules 下的正確node_modules
依賴項。
更新:根據您的評論和編輯的問題,我嘗試使用 CRA 重現此內容,替換package.json
中的依賴項,重新安裝並添加以下.eslintrc
。
請注意,我在"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": "^_$"
}]
}
}
完成所有這些后,我無法重現該問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.