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

ndasle7k  于 2023-03-17  发布在  React
关注(0)|答案(3)|浏览(321)

问题

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

如何生产

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

软件包. 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"
  }
}

我试图找到解决办法,但失败了。我恳请你的帮助。

yx2lnoni

yx2lnoni1#

将此添加到您的配置中:

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

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

xxhby3vn

xxhby3vn2#

在您的folder root编辑.eslintrc.js文件,并把"version": "detect" .喜欢

module.exports = {
  settings: {
    react: {
     version: "detect",
    },
  },
 }
bakd9h0s

bakd9h0s3#

问题出在eslint-plugin-react v.7.30.1中,请将其降级到v.7.30.0,它将正常工作

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

相关问题