Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning: React version not specified in eslint-plugin-react settings. #1955

Closed
kud opened this issue Aug 22, 2018 · 57 comments · Fixed by #1978
Closed

Warning: React version not specified in eslint-plugin-react settings. #1955

kud opened this issue Aug 22, 2018 · 57 comments · Fixed by #1978

Comments

@kud
Copy link
Contributor

kud commented Aug 22, 2018

Hello,

Since I've updated this plugin, i've got a message like Warning: React version not specified in eslint-plugin-react settings..

This is true, I didn't specify the version of react, and this happens due to 8738e59#diff-4e51c5c91adee02670adaca34f7fd7fdR17

However, when I read the doc, I've got this:

"version": "15.0", // React version, default to the latest React stable release

It's said "by default, it uses the latest version of react".

So why displaying a warning if there's a default and this is what I want? as I keep my react often upgraded.

@ljharb
Copy link
Member

ljharb commented Aug 22, 2018

(linking to your comment here: #1857 (comment))

@ljharb
Copy link
Member

ljharb commented Aug 22, 2018

Just because there's a default doesn't mean you shouldn't always be providing an explicit value.

Repeating #1857 (comment):

i could see adding a separate option for "detect" (using the "version" as a fallback), which did require('react').version - want to open a PR that adds that?
(Note that it'd have to use process.cwd(), and the resolve package, to get the proper require path)

@kud
Copy link
Contributor Author

kud commented Aug 22, 2018

Yes, it's true.

For the moment, I use this workaround: "version": "999.999.999".

@chrisdothtml
Copy link

+1 for supporting latest as the value

@marcofugaro
Copy link
Contributor

Yeah please I don't want to update this config each time a new react comes out

@ljharb
Copy link
Member

ljharb commented Aug 28, 2018

You have to update your package.json every time that happens; I’m not sure also updating eslintrc is much harder.

@marcofugaro
Copy link
Contributor

Yeaaah... I don't have it in a package.json, I have it in the eslint config shared for the team, and each time I would have to upgrade deps, update by hand, publish a new version of the tool.

Most importantly, I upgrade my dependencies using yarn upgrade-interactive --latest, not by hand. I (or other mantainers) might forget to update this version by hand.

@chrisdothtml
Copy link

We also use a shared eslint config and this would make it quite annoying every upgrade. If "latest" isn't supported, everyone's just gonna use "999.999.999" instead, which could lead to issues in the future if this plugin assumes that property contains their actual React version

@kud
Copy link
Contributor Author

kud commented Aug 29, 2018

#1955 (comment)

Well, I use ncu to update my packages, and yes it's not hard to update .eslintrc but you have to remember this and it's not something I want. :D

I'm using 999.999.999 for the moment.

@bhardy
Copy link

bhardy commented Aug 29, 2018

Comment removed and new issue created: #1963

@ljharb
Copy link
Member

ljharb commented Aug 30, 2018

@bhardy that seems like a different issue; if you have the settings object with a react version you shouldn't get a warning at all.

@bhardy
Copy link

bhardy commented Aug 30, 2018

@ljharb would you like me to create a new issue?

@ljharb
Copy link
Member

ljharb commented Aug 30, 2018

@bhardy yes please :-)

Timer added a commit to Timer/create-react-app that referenced this issue Sep 20, 2018
This is the best behavior so people have seamless upgrades to new React majors.

This is probably a terrible default and warning from the ESLint plugin, and we need to wait for jsx-eslint/eslint-plugin-react#1955 before changing this hardcoded behavior.

Closes facebook#5034
Timer added a commit to Timer/create-react-app that referenced this issue Sep 20, 2018
This is the best behavior so people have seamless upgrades to new React majors.

This is probably a terrible default warning from the ESLint plugin, and we need to wait for jsx-eslint/eslint-plugin-react#1955 before changing this hardcoded behavior.

Closes facebook#5034
@mohsinulhaq
Copy link
Contributor

I tried {"version": "latest"}, and it's working fine. Why are we pushing for '999.999.999'?

@ljharb
Copy link
Member

ljharb commented Sep 23, 2018

@mohsinulhaq it would be more explicit than relying on React never hitting v999

@mohsinulhaq
Copy link
Contributor

but there is no downside of using latest with regards to linting, right?

@ljharb
Copy link
Member

ljharb commented Sep 23, 2018

The downside would be a lack of explicit configuration with respect to which React version you’re using, i suppose.

zmitry pushed a commit to zmitry/create-react-app that referenced this issue Sep 30, 2018
This is the best behavior so people have seamless upgrades to new React majors.

This is probably a terrible default warning from the ESLint plugin, and we need to wait for jsx-eslint/eslint-plugin-react#1955 before changing this hardcoded behavior.

Closes facebook#5034
@anilanar
Copy link

anilanar commented Oct 10, 2018

I think this is an important bug. There are editor plugins that rely on exit code and stdout of eslint --fix/prettier-eslint for auto-formatting.

As a formatter, prettier-eslint must not log something to stdout when exit code is 0.

@bertho-zero
Copy link

bertho-zero commented Oct 10, 2018

@anilanar Even when the version is filled the warning appears with prettier-eslint, I fixed that and I wait for a response. (prettier/prettier-eslint#194)

@samhou1988
Copy link

.eslintrc.js
settings: {
    react: {
        version: 'detect',
    },
}

wholemann added a commit to wholemann/react-week1-assignment-1 that referenced this issue May 5, 2021
Fix the warning of React version not speicifed
in eslint-plugin-react settings.

See also:
- jsx-eslint/eslint-plugin-react#1955
wholemann added a commit to wholemann/react-week1-assignment-1 that referenced this issue May 5, 2021
Fix the warning of React version not speicifed
in eslint-plugin-react settings.

See also:
- jsx-eslint/eslint-plugin-react#1955
eagerdev12 added a commit to eagerdev12/creating-app that referenced this issue Dec 27, 2021
This is the best behavior so people have seamless upgrades to new React majors.

This is probably a terrible default warning from the ESLint plugin, and we need to wait for jsx-eslint/eslint-plugin-react#1955 before changing this hardcoded behavior.

Closes #5034
@vadimimmel

This comment was marked as spam.

@tjx666

This comment was marked as resolved.

@ljharb

This comment was marked as resolved.

@daryazata
Copy link

Simply need to write exact version of react you re using ..

@ljharb
Copy link
Member

ljharb commented Jun 16, 2022

@daryazata it supports "detect", so you shouldn't have to do that.

@MidKnightXI
Copy link

For people using .yml instead of .js or .json you just need to add it like that to your .eslintrc.yml

...
settings:
  react:
    version: "detect"

@julielouie
Copy link

julielouie commented Sep 22, 2022

Hi there, I seem to still be having this issue on v7.31.8, and would love some insight if I'm just setting things up incorrectly.
This is a brand new React/TS project being set up using VS Code, so what you see is all I have currently.
The eslint library is being loaded in successfully, and I don't have any errors, but I am still getting this warning:
Screen Shot 2022-09-22 at 1 26 35 PM

The contents of my .eslintrc.js:

module.exports = {
  root: true,
  env: {
    node: true,
    browser: true
  },
  parser: '@typescript-eslint/parser',
  parserOptions: {
    ecmaVersion: 2022,
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true
    },
    settings: {
      react: {
        version: 'detect'
      },
      'import/resolver': {
        node: {
          paths: ['src'],
          extensions: ['.js', '.jsx', '.ts', '.tsx']
        }
      }
    }
  },
  extends: [
    'eslint:recommended',
    'plugin:react/recommended',
    'plugin:import/recommended',
    'plugin:import/typescript',
    'plugin:@typescript-eslint/recommended',
    'eslint-config-prettier'
  ],
  rules: {
    'react/react-in-jsx-scope': 'off',
    semi: [2, 'always']
  }
};

The contents of my package.json:

{
  "name": "project",
  "private": true,
  "version": "0.0.0",
  "scripts": {
    "dev": "vite",
    "build": "tsc && vite build",
    "preview": "vite preview",
    "lint": "eslint . --ext .ts,.tsx"
  },
  "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
  "devDependencies": {
    "@types/react": "^18.0.17",
    "@types/react-dom": "^18.0.6",
    "@typescript-eslint/eslint-plugin": "^5.38.0",
    "@typescript-eslint/parser": "^5.38.0",
    "@vitejs/plugin-react": "^2.1.0",
    "eslint": "^8.23.1",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-import": "^2.26.0",
    "eslint-plugin-react": "^7.31.8",
    "prettier": "^2.7.1",
    "typescript": "^4.6.4",
    "vite": "^3.1.0"
  }
}

Current file structure:
Screen Shot 2022-09-22 at 1 25 27 PM

@ljharb
Copy link
Member

ljharb commented Sep 22, 2022

@juliehchung try running eslint on the command line. if it works, then the problem is in your editor; if not, then please file a new issue, ideally with a repro repo.

@julielouie
Copy link

@juliehchung try running eslint on the command line. if it works, then the problem is in your editor; if not, then please file a new issue, ideally with a repro repo.

Do you mind elaborating what you mean by this? The same warning still pops up when running eslint via the cli, but it will still run without errors.

@ljharb
Copy link
Member

ljharb commented Sep 22, 2022

I mean running npx eslint ., outside of vscode.

If the same warning pops up, then I'd love a new issue with a repro repo :-)

@julielouie
Copy link

julielouie commented Sep 22, 2022

I mean running npx eslint ., outside of vscode.

If the same warning pops up, then I'd love a new issue with a repro repo :-)

Submitted here #3438

tylim88 added a commit to Outerbridgeio/Outerbridge that referenced this issue Oct 8, 2022
- eslint-import-resolver-typescript
- eslint-plugin-flowtype
- eslint-plugin-import

2. stop eslint from nagging react version not specified
jsx-eslint/eslint-plugin-react#1955 (comment)

3. remove redundant eslint config and rules

4. use popular recommended setting for easier config management and modern practices
WebWizrd8 added a commit to WebWizrd8/event-listener that referenced this issue Feb 21, 2024
- eslint-import-resolver-typescript
- eslint-plugin-flowtype
- eslint-plugin-import

2. stop eslint from nagging react version not specified
jsx-eslint/eslint-plugin-react#1955 (comment)

3. remove redundant eslint config and rules

4. use popular recommended setting for easier config management and modern practices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.