我正在做一个在节点10上运行的项目,"react":"^17.0.1“。“react脚本”:"^4.0.1“
在每个项目开始时都会显示许多警告,例如使用==而不是===等等。
下面是脚本的一部分,启动原始脚本,另一个脚本是我添加的,试图找到一个解决方案:
"scripts": {
"start": "env-cmd -f .env.dev --use-shell \"react-scripts start\"",
"lint": "eslint src --ext .js,.jsx",
"lint:fix": "npm run lint -- --fix",
"eslint": "eslint \"src/**/*.{js,jsx}\" --fix"
},我想运行eslint自动修复警告。我试过命令:
eslint "src/**/*.{js,jsx}" --fix
npm run eslint;
npm run lint不管我运行什么命令,我都会得到这样的错误消息:✖312个问题(3个错误,309个警告)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! company@1.0.0 lint: `eslint src --ext .js,.jsx`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the company@1.0.0 lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/myname/.npm/_logs/2022-04-14T12_48_51_948Z-debug.log或者:
✖312个问题(3个错误,309个警告)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! company@1.0.0 lint: `eslint src --ext .js,.jsx "--fix"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the company@1.0.0 lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/myname/.npm/_logs/2022-04-14T12_57_18_764Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! company@1.0.0 lint:fix: `npm run lint -- --fix`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the company@1.0.0 lint:fix script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/myname/.npm/_logs/2022-04-14T12_57_18_794Z-debug.log在package.json中有以下信息:
"eslintConfig": {
"extends": [
"react-app"
]
},没有安装在package.json - is中的eslink包应该使用嵌入的eslint脚本。
有没有人知道如何使隐形眼镜修复许多没有人关心的警告呢?
编辑:可能在警告列表之后出现此错误,因为在中间也有一些错误,例如:
在这里,文件10:41的路径在函数"betaBanner“中调用error function”betaBanner“,该函数既不是function函数组件,也不是自定义React函数。rules组件名称必须以大写字母rules hooks/规则-hooks开头。
编辑2:是的,在我手动更正了它现在用黄色✖ 309 problems (0 errors, 309 warnings)写的两个错误之后,最后的错误消失了。
发布于 2022-04-14 13:22:46
有时,重新安装node_modules会为我修复这些问题。
以下是我所遵循的步骤:
干净的npm缓存:npm cache clean --force
删除node_modules文件夹和package-lock.json文件。
执行一个新的包安装:npm install
启动项目:npm start
对于VS代码,可以尝试在VS代码settings.json中添加这些设置
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.fixAll.tslint": true,
"source.fixAll.stylelint": true
},发布于 2022-09-04 19:48:50
将此配置添加到.eslintrc配置文件中
"react-hooks/exhaustive-deps": [
"warn",
{
"enableDangerousAutofixThisMayCauseInfiniteLoops": true
}
]在这里阅读更多关于这个问题的https://github.com/facebook/react/issues/18235#issuecomment-898636301
https://stackoverflow.com/questions/71872073
复制相似问题