我有一个用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"
}
这是我的.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"
}
}
发布于 2021-09-08 22:53:47
我也遇到了同样的问题。我通过从package.json中删除现有的eslint-config-prettier和eslint-plugin-prettier解决了这个问题。然后重新安装yarn (或npm)作为依赖项(而不是dev-依赖项)。然后我又把它推给heroku,它起作用了!
发布于 2021-11-05 17:19:45
也有同样的问题。为了解决这个问题,我将eslint从8.3.0
版本降级为
"eslint": "^7.32.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-prettier": "^3.4.1",
https://stackoverflow.com/questions/65397827
复制相似问题