reactjseslint

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 . while running eslint.

How to produce

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

package.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.


Solution

  • Add this to your config in .eslintrc:

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

    See the config here: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/README.md#configuration