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

Error while loading rule 'react/prefer-stateless-function': Cannot read property 'version' of null Occurred while linting #3219

Closed
tipleavalentin opened this issue Feb 25, 2022 · 5 comments

Comments

@tipleavalentin
Copy link

tipleavalentin commented Feb 25, 2022

Hi!

I found a bug, please take a look, thanks!

npx eslint src_site/pages/HomePage.js

Oops! Something went wrong! :(

ESLint: 8.8.0

TypeError: Error while loading rule 'react/prefer-stateless-function': Cannot read properties of null (reading 'version')
Occurred while linting D:\project\src_site\pages\HomePage.js
at getReactVersionFromContext (D:\project\node_modules\eslint-plugin-react\lib\util\version.js:92:81)
at testReactVersion (D:\project\node_modules\eslint-plugin-react\lib\util\version.js:138:28)
at usedPropTypesInstructions (D:\project\node_modules\eslint-plugin-react\lib\util\usedPropTypes.js:285:36)
at Function.componentRule (D:\project\node_modules\eslint-plugin-react\lib\util\Components.js:1018:37)
at createRuleListeners (D:\project\node_modules\eslint\lib\linter\linter.js:915:21)
at D:\project\node_modules\eslint\lib\linter\linter.js:1097:31
at Array.forEach ()
at runRules (D:\project\node_modules\eslint\lib\linter\linter.js:1034:34)
at Linter._verifyWithoutProcessors (D:\project\node_modules\eslint\lib\linter\linter.js:1382:31)
at Linter._verifyWithConfigArray (D:\project\node_modules\eslint\lib\linter\linter.js:1722:21)

image

@tipleavalentin
Copy link
Author

In .eslintrc I have:
"settings": {
"react": {
"version": "latest"
}
}

With version: "17.0.2" it doesn't throw this error.

@ljharb
Copy link
Member

ljharb commented Feb 25, 2022

Thanks, fix incoming.

@ljharb
Copy link
Member

ljharb commented Feb 25, 2022

Actually, the issue is that "latest" is an invalid value. It supports a semver version range, or "detect". "latest" is not a semver range, it's just an npm tag.

I'll try to improve the error message here, and avoid a crash, but you'll still need to fix your eslint config.

@ljharb ljharb closed this as completed in 5dd50fa Feb 25, 2022
@ljharb
Copy link
Member

ljharb commented Feb 25, 2022

v7.29.1 is released.

@tipleavalentin
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants