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

Most upvoted comments

Sorry. That solved the problem. npm install -g eslint-plugin-react

solved by ⬇️

$ cd ~/.atom/packages/linter-eslint
$ npm i eslint-plugin-react

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:

"scripts": {
    "lint": "eslint ."
}

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:

$ node_modules/.bin/eslint .

Does this help at all?

Thanks @IanVS and @DelvarWorld It was a combination of:

rm -rf node_modules && npm uninstall -g eslint eslint-plugin-react

and

npm install --save-dev eslint eslint-plugin-react && npm install

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 and npm cache clear did nothing. For me the issue was some combination of nvm and global eslint. I had to npm uninstall -g eslint, then install it for the specific project npm install eslint, then close my shell and open a new session, because in my old shell when I ran eslint 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 into linter-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, so linter-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

I’ve managed to solve the issue only after deleting the node_modules directory from my home directory

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?