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

ESLint: Error while loading rule 'react/display-name': Cannot find module 'react' #2329

Closed
TidyIQ opened this issue Jun 25, 2019 · 13 comments
Closed

Comments

@TidyIQ
Copy link

TidyIQ commented Jun 25, 2019

I have a custom config file, which can be found here:

For some reason when I attempt to use this custom config in a project, I get the following error:

ESLint: Error while loading rule 'react/display-name': Cannot find module 'react' from 'C:\Users\Me\Websites' Occurred while linting C:\Users\Me\Websites\Templates\core\src\config\next\_app.tsx. 

The plugin is installed at C:\Users\Me\Websites\Templates\core\node_modules\eslint-plugin-react.

This only occurs for this plugin. I don't have this issue with any other plugins I use. Everything appears to be setup correctly so I believe this is a bug with eslint-plugin-react.

@ljharb
Copy link
Member

ljharb commented Jun 25, 2019

Do you have react installed, in C:\Users\Me\Websites\Templates\core\node_modules\?

Specifically, by setting the version to "detect", you're forcing react to be installed so the plugin can detect its version.

@TidyIQ
Copy link
Author

TidyIQ commented Jun 25, 2019

Yep, it's installed and located there.

@ljharb
Copy link
Member

ljharb commented Jun 25, 2019

what's the path to package.json? in which dir are you running eslint?

@TidyIQ
Copy link
Author

TidyIQ commented Jun 25, 2019

C:\Users\Me\Websites\Templates\core\package.json and I'm running eslint from C:\Users\Me\Websites\Templates\core.

I've literally just discovered that this appears to only be an issue for this plugin (and only this plugin) with vscode-eslint only. Running eslint from the cli doesn't return the error, it only appears in the vscode ESLint extension. I've created an issue in the vscode-eslint repo so perhaps they'll discover the issue is on their end.

@ljharb
Copy link
Member

ljharb commented Jun 25, 2019

Ah, gotcha - in that case I'd say it's an issue with vscode-eslint, probably not setting the require path correctly.

eslint 6 requires fully resolved paths in places it didn't before, so this problem will likely crop up much more often for them.

Closing this (and i'd suggest closing eslint/eslint#11891) in favor of microsoft/vscode-eslint#695.

@ljharb ljharb closed this as completed Jun 25, 2019
fastfrwrd pushed a commit to spotify/web-scripts that referenced this issue Jun 26, 2019
peerDependencies in the packages were throwing warnings, potentially related to
yarnpkg/yarn#5810. In this commit, we rework the peerDependency
definitions to align better with the conventions outlined in the main peerDependency documentation,
and we define devDependencies both at the top level and at the package level, since package-level is
technically closer to "correct" but it doesn't satisfy the checks in yarn yet. In addition, we've
bumped a few versions and aligned across the packages where duplication occurs, which led to our
tests running into jsx-eslint/eslint-plugin-react#2329 for our "detect"
mode in eslint-plugin-react.
fastfrwrd pushed a commit to spotify/web-scripts that referenced this issue Jun 26, 2019
peerDependencies in the packages were throwing warnings, potentially related to
yarnpkg/yarn#5810. In this commit, we rework the peerDependency
definitions to align better with the conventions outlined in the main peerDependency documentation,
and we define devDependencies both at the top level and at the package level, since package-level is
technically closer to "correct" but it doesn't satisfy the checks in yarn yet. In addition, we've
bumped a few versions and aligned across the packages where duplication occurs, which led to our
tests running into jsx-eslint/eslint-plugin-react#2329 for our "detect"
mode in eslint-plugin-react.
@davidysoards
Copy link

I'm having the same issue. It seems to be looking for the "react" module in the parent directory instead of the project root directory. Extremely frustrating

@MoOx
Copy link
Contributor

MoOx commented Jul 12, 2019

Same problem here, without vscode. I am getting this from CLI.
eslint & eslint-plugin-react are close to each other in node_modules.

@ljharb
Copy link
Member

ljharb commented Jul 12, 2019

@MoOx is this also on windows?

@MoOx
Copy link
Contributor

MoOx commented Jul 12, 2019

No macOS.

@ljharb
Copy link
Member

ljharb commented Jul 12, 2019

Can you file a new issue?

@sgehrman
Copy link

sgehrman commented Jul 12, 2019

Happens for me too. I'm on Linux.

This version works:

"eslint-plugin-react": "7.11.1",

New versions are broken.

@edhollinghurst
Copy link

If you're having this issue whilst using the ESLint VSCode extension, I was able to fix it by adding this to my VSCode settings.json:

"eslint.workingDirectories": [
  {
    "mode": "auto" // Working directory based on the location of package.json, .eslintignore and .eslintrc* files
  }
]

@TahseenAlaa
Copy link

Problem solved after update npm dependencies:

npm update

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

7 participants