首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >艾斯林特在反应中没有纠正错误

问艾斯林特在反应中没有纠正错误
EN

Stack Overflow用户
提问于 2022-04-14 13:00:08
回答 2查看 626关注 0票数 0

我正在做一个在节点10上运行的项目,"react":"^17.0.1“。“react脚本”:"^4.0.1“

在每个项目开始时都会显示许多警告,例如使用==而不是===等等。

下面是脚本的一部分,启动原始脚本,另一个脚本是我添加的,试图找到一个解决方案:

代码语言:javascript
复制
"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自动修复警告。我试过命令:

代码语言:javascript
复制
eslint "src/**/*.{js,jsx}" --fix
npm run eslint;
npm run lint

不管我运行什么命令,我都会得到这样的错误消息:✖312个问题(3个错误,309个警告)

代码语言:javascript
复制
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个警告)

代码语言:javascript
复制
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中有以下信息:

代码语言:javascript
复制
"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)写的两个错误之后,最后的错误消失了。

EN

回答 2

Stack Overflow用户

发布于 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中添加这些设置

代码语言:javascript
复制
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
    "source.fixAll.eslint": true,
    "source.fixAll.tslint": true,
    "source.fixAll.stylelint": true
},
票数 0
EN

Stack Overflow用户

发布于 2022-09-04 19:48:50

将此配置添加到.eslintrc配置文件中

代码语言:javascript
复制
"react-hooks/exhaustive-deps": [
       "warn",
        {
          "enableDangerousAutofixThisMayCauseInfiniteLoops": true
        }
      ]

在这里阅读更多关于这个问题的https://github.com/facebook/react/issues/18235#issuecomment-898636301

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71872073

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档