Add this to your config in ESLint Config File, i.e. .eslintrc or eslint.config.js
{
"settings": {
"react": {
"version": "detect"
}
}
}
See the config here: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/README.md#configuration
Docs
https://eslint.org/docs/
https://eslint.org/docs/latest/use/configure/migration-guide
https://eslint.org/docs/latest/use/configure/configuration-files
Answer from Mark on Stack OverflowAdd this to your config in ESLint Config File, i.e. .eslintrc or eslint.config.js
{
"settings": {
"react": {
"version": "detect"
}
}
}
See the config here: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/README.md#configuration
Docs
https://eslint.org/docs/
https://eslint.org/docs/latest/use/configure/migration-guide
https://eslint.org/docs/latest/use/configure/configuration-files
If you're looking at the new eslint.config.js, I did the below (with typescript). I tried to follow the official README but it wasn't too helpful.
import react from "eslint-plugin-react";
import typescriptEslint from "@typescript-eslint/eslint-plugin";
import typescriptParser from "@typescript-eslint/parser";
import globals from "globals";
import reactRecommended from "eslint-plugin-react/configs/recommended.js";
export default [
{
ignores: ["dist/**/*"],
},
{
files: ["**/*.{js,jsx,mjs,cjs,ts,tsx}"],
ignores: ["dist/**/*"],
...reactRecommended,
settings: {
version: "detect",
},
languageOptions: {
...reactRecommended.languageOptions,
ecmaVersion: "latest",
sourceType: "module",
parser: typescriptParser,
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
globals: {
...globals.serviceworker,
...globals.browser,
},
},
plugins: {
"@typescript-eslint": typescriptEslint,
react,
},
rules: {
//rules here
},
},
];
» npm install eslint-plugin-react
There will be an Object defined in your .eslintrc file as settings. And this error is saying that the version of react defined in it is not the version installed in your machine. Please replace settings object with following code so that es lint can detect it automatically on runtime.
"settings": {
"react": {
"version": "detect"
}
}
Just add the code in the .eslintrc file (js,json) as this eslint will automatically detect the react version
"plugins": [
...
],
"settings": {
"react": {
"version": "detect"
}
},
"rules": {
...
}
You can read about it in React docs.
If you are using
eslint-plugin-react, thereact/jsx-uses-reactandreact/react-in-jsx-scoperules are no longer necessary and can be turned off or removed.
{
// ...
"rules": {
// ...
"react/jsx-uses-react": "off",
"react/react-in-jsx-scope": "off"
}
}
react-in-jsx-scopeon github.
To make it work, you should add those rules to your eslint config, see Extending or replacing the default ESLint config for Create-React-App specifics, every framework should have related section in their docs.
You need to add plugin:react/jsx-runtime to extends in the .eslintrc.js file.
like is:
module.exports = {
extends: [
'plugin:react/recommended',
'plugin:react/jsx-runtime',
]
}
Maybe a warning: Warning: React version not specified in eslint-plugin-react settings. See https://github.com/jsx-eslint/eslint-plugin-react#configuration .
You need to set like this
module.exports = {
extends: [
'plugin:react/recommended',
'plugin:react/jsx-runtime',
],
"settings": {
"react": {
"version": "detect"
}
},
}
Refer here
When you see a warning like this:
Warning: React version not specified in eslint-plugin-react settings. See https://github.com/yannickcr/eslint-plugin-react#configuration .
Try adding React version settings in your eslint configuration file, such as .eslintrc.js, like below:
// .eslintrc.js
{
...
settings: {
react: {
version: 'detect',
},
},
}
module.exports = {
env: {
browser: true,
es2021: true,
jest: true,
'react-native/react-native': true,
},
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:react-native/all',
],
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 12,
sourceType: 'module',
},
plugins: ['react', 'react-hooks', 'react-native'],
rules: {
'react/jsx-filename-extension': [1, { extensions: ['.js', '.jsx'] }],
'global-require': 0,
'operator-linebreak': [2, 'before'],
},
settings: {
react: {
version: "detect"
}
}
};