eslint: Error: Cannot find module 'eslint-plugin-react'
Fresh global installation, first test and error 😦 Any ideas?
pawelgrzybek$ eslint js/script1.js
module.js:338
throw err;
^
Error: Cannot find module 'eslint-plugin-react'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:286:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at /usr/local/lib/node_modules/eslint/lib/cli-engine.js:116:26
at Array.forEach (native)
at loadPlugins (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:107:21)
at processText (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:194:5)
at processFile (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:254:18)
at executeOnFile (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:540:23)
pawelgrzybek$
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 32 (9 by maintainers)
Commits related to this issue
- Fix semistandard in Travis-CI [iet:8760510] * semistandard: Unexpected linter output: Error: Failed to load plugin react: Cannot find module 'eslint-plugin-react' * Related? https://github.com/eslint... — committed to IET-OU/moodle-auth_ouopenid by nfreear 7 years ago
- Fix semistandard on Travis-CI * semistandard: Unexpected linter output: Error: Failed to load plugin react: Cannot find module 'eslint-plugin-react' * eslint-plugin-react@6.10.3 NOT @7.1.0 * https:... — committed to nfreear/popup-geojson-map by nfreear 7 years ago
Sorry. That solved the problem.
npm install -g eslint-plugin-react
solved by ⬇️
The basic thing to keep in mind is that the plugins need to be installed wherever you are running eslint. If you are typing
eslint
into your terminal, you are running the globally installed eslint (unless of course you’ve set up an alias or changed your PATH variable, but that’s rare).Typically we suggest that you install eslint and any plugins locally (
npm install --save-dev eslint eslint-plugin-react
without the-g
flag). Then, set up an npm script as something like this:Be sure to use whatever directory and options apply to you. Then, when you want to lint your files, use
npm run lint
, and npm will use the local version and won’t try to run a global eslint.The other way to run the local eslint is a little more clunky, but can be done with:
Does this help at all?
Thanks @IanVS and @DelvarWorld It was a combination of:
and
Added the trailing npm install to compensate for rm’ing node_modules entirely, just in case anyone copy/pastes this without looking 😉
I ran into this error too and
rm -rf node_modules
,npm cache clean
andnpm cache clear
did nothing. For me the issue was some combination of nvm and global eslint. I had tonpm uninstall -g eslint
, then install it for the specific projectnpm install eslint
, then close my shell and open a new session, because in my old shell when I raneslint
it kept trying to run my old global version in the nvm node_modules directory.tl;dr I don’t know where I am or what’s happening
^ While this will work, it is not the best way to address the issue. This installs
eslint-plugin-react
intolinter-eslint
directly. The reason it’s solving it for you is that you don’t have ESLint installed in your own project and you don’t have ESLint installed globally, solinter-eslint
is falling back to the the version of ESLint that it bundles as a backup. There have been discussions that we may stop bundling it in the future, because of the confusion it causes, not knowing what ESLint you’re actually using.The best thing to do is to install eslint and any necessary plugins into your project with
npm install --save-dev eslint eslint-plugin-react
. This will ensure that everyone contributing to your project is using the right version of ESLint.@pawelgrzybek seems to have nailed it.
npm install -g eslint-plugin-react
This fixed Atom for me.
@BYK. You are correct, I just discovered that eslint was installed globally, but not locally, so the reason it couldn’t find eslint-plugin-react was because the global version of eslint couldn’t find the locally installed version, which is correct behavior. User error, not eslint error.
You must have had eslint installed somewhere, maybe globally? How did you run eslint to get the error if it wasn’t installed?