简体   繁体   English

警告:在 React 18.2.0 之上运行 eslint 时,“eslint-plugin-react 设置”中未指定 React 版本

[英]Warning: React version not specified in 'eslint-plugin-react settings' while running eslint on top of React 18.2.0

Issue问题

Git bash shows Warning: React version not specified in eslint-plugin-react settings. See https://github.com/jsx-eslint/eslint-plugin-react#configuration . Git bash 显示Warning: React version not specified in eslint-plugin-react settings. See https://github.com/jsx-eslint/eslint-plugin-react#configuration . Warning: React version not specified in eslint-plugin-react settings. See https://github.com/jsx-eslint/eslint-plugin-react#configuration . while running eslint.在运行 eslint 时。

How to produce如何生产

create-react-app my-app
cd app
npm install eslint --save-dev
npx eslint --init
npx eslint .

package.json包.json

{
  ...
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.4",
    "@testing-library/react": "^13.3.0",
    "@testing-library/user-event": "^13.5.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4"
  },
  ...
  "devDependencies": {
    "eslint": "^8.18.0",
    "eslint-plugin-react": "^7.30.1"
  }
}

I tried to find solutions but failed.我试图找到解决方案但失败了。 I kindly ask for your help.我恳请您的帮助。

Add this to your config:将此添加到您的配置中:

{
  "settings": {
    "react": {
      "version": "detect"
    }
  }
}

See the config here: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/README.md#configuration在此处查看配置: https ://github.com/jsx-eslint/eslint-plugin-react/blob/master/README.md#configuration

The problem is in the eslint-plugin-react v.7.30.1.问题出在eslint-plugin-react v.7.30.1 中。 Downgrade it to v.7.30.0 and it will work将其降级到 v.7.30.0 即可使用

"eslint-plugin-react": "^7.30.0"

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

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