Error: Cannot find module 'eslint/lib/rules/no-unused-expressions'

Viewed 16800

After installing ESLint through NPM, I'm getting the following error in my browser:

Error: Cannot find module 'eslint/lib/rules/no-unused-expressions' Referenced from:

Any idea what could cause this and how I can fix it?

6 Answers

Try these steps:

  1. Delete package-lock.json file
  2. Delete node_modules folder
  3. Delete .eslintrc file
  4. Remove devDependencies that contains 'eslint'
  5. In the terminal type: npm install
  6. In the terminal type: npm run start

In case you want to have eslint, try checking if you have in your devDependencies the line below:

"eslint": "5.6.0"
  1. NPM INSTALL ESLINT

I had this issue while using a create-react-app. React scripts already come with an eslint version installed and that means you shouldn't need to install eslint on your own. I fixed this issue by doing the following:

  1. Deleted node-modules folder
  2. Deleted my package-lock.json file
  3. Removed my local installation of eslint from the package.json file
  4. Installed all packages again npm install
  5. npm start and everything was working fine again

Deleted node-modules folder
Deleted my package-lock.json file
Removed eslint from the package.json file
Installed all packages again

npm install   
npm start 

and everything was working fine again

Easy fix #1

npm i -D --save eslint-loader

Easy fix #2

npm i -D --save eslint@5.16.0

Explanation:

  • If you look at the error stack trace you'll see the error is actually fired from eslint-loader/index.js (so not eslint).
  • Then in node_modules, you can find eslint-loader and check the version in its package.json. It's probably quite outdated. Mine was at 1.9.0, while the current version of eslint-loader is 4.0.2
  • And back to the error - that path that it is complaining about apparently did get changed from eslint/lib/formatters/stylish to eslint/lib/formatters/<some-other-folder>/stylish in a newer version of eslint (I think v6). And now this older eslint-loader version is failing to find the updated path in eslint.

So either upgrading eslint-loader to a newer version that knows this new path (Easy fix 1), or downgrading eslint down to when it had that old path (Easy fix 2), should both work.

For the record I think this outdated dependency is coming from webpack, which makes it difficult to debug for the create-react-app folks.

Make sure you clean your node_modules. Delete your package-lock.json. and run the

npm cache clean --force to clean the cache. Now install the eslint by running below in the directory:

npm i --save eslint

I know it's late to answer, maybe it's gonna help someone who comes to this thread.

for linux user and using npx just type npx eslint --init as the documentation says

Related