简体   繁体   English

如何禁用浏览器中显示的 eslint 错误

[英]How to disable eslint errors showing in the browser

When I run my create react app application using npm start, the eslint errors are shown in the browser on top of my site.当我使用 npm start 运行我的 create react app 应用程序时,eslint 错误显示在我网站顶部的浏览器中。 I expect to see these warnings and errors in the terminal but not in the actual website, how can I remove this?我希望在终端中看到这些警告和错误,但在实际网站中看不到,我该如何删除它?

在此处输入图像描述

package.json package.json

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.11.0",
    "react-dom": "^16.11.0",
    "react-router-dom": "^5.1.2",
    "react-scripts": "^5.0.0",
    "react-transition-group": "^4.3.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "lint": "eslint ."
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "eslint": "^8.12.0",
    "eslint-config-airbnb": "^19.0.4",
    "eslint-plugin-import": "^2.25.4",
    "eslint-plugin-jsx-a11y": "^6.5.1",
    "eslint-plugin-react": "^7.29.4",
    "eslint-plugin-react-hooks": "^4.4.0"
  }
}

You can disable errors in browser by adding the environment variable ESLINT_NO_DEV_ERRORS as it is mentioned here .您可以通过添加此处提到的环境变量ESLINT_NO_DEV_ERRORS来禁用浏览器中的错误。

If you have .env file in your project, just add this line to it, and re-build the app:如果您的项目中有.env文件,只需将此行添加到其中,然后重新构建应用程序:

ESLINT_NO_DEV_ERRORS=true

Inside eslint.rc you will have section for your env within module.exports you can add false to the browser parameter, this will also fix this issue在 eslint.rc 中,您将在 module.exports 中为您的环境设置部分,您可以将 false 添加到浏览器参数中,这也将解决此问题

 env: { browser: false, es2021: true, node: true, },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM