![](/img/trans.png)
[英]Dealing with "Failed to load plugin 'react' declared in '.eslintrc': Cannot find module 'eslint-plugin-react'" ESLint error
[英]Failed to load plugin 'prettier' declared in '.eslintrc.json': Cannot find module 'eslint-plugin-prettier'
我有一個使用 react 制作的前端項目,可以在 vsCode 上完美運行,但是當我將它上傳到 Heroku 時,我收到了這個錯誤:
Failed to load plugin 'prettier' declared in '.eslintrc.json': Cannot find module 'eslint-plugin-prettier'
Require stack:
- /app/node_modules/react-scripts/config/__placeholder__.js
Referenced from: /app/.eslintrc.json
我試圖卸載 eslint 並再次安裝它,但它沒有工作。 而且由於我有點新,我不知道我應該在哪里尋找答案。
這是我的 package.json 的一部分:
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"devDependencies": {
"eslint": "^7.16.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^7.1.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.3.0",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.2.0",
"prettier": "2.2.1"
}
這是 my.eslintrc.json
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"plugin:react/recommended",
"plugin:prettier/recommended"
],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"react",
"prettier"
],
"rules": {
"no-console": "off",
"prettier/prettier": ["error"],
"consistent-return": "off",
"react/jsx-indent": "off",
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"implicit-arrow-linebreak": "off",
"react/button-has-type": "off",
"jsx-a11y/label-has-associated-control": "off",
"no-plusplus": "off",
"react/prop-types": "off"
}
}
我遇到了完全相同的問題。 我通過從 package.json 中刪除現有的eslint-config- prettier 和eslint-plugin- prettier 解決了這個問題。 然后在重新安裝紗線(或 npm)作為依賴項(而不是開發依賴項)之后。 然后我又把它推到了 heroku,它成功了!
有同樣的問題。 為了解決這個問題,我將 eslint 從8.3.0
版本降級到
"eslint": "^7.32.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-prettier": "^3.4.1",
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.