Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 499
SyedKhizer Avatar asked Oct 23 '18 17:10

SyedKhizer


4 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
like image 94
Roger Oliveira Avatar answered Nov 16 '22 11:11

Roger Oliveira


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
like image 35
William Avatar answered Nov 16 '22 10:11

William


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

like image 1
anjeev Avatar answered Nov 16 '22 10:11

anjeev


Easy fix #1

npm i -D --save eslint-loader

Easy fix #2

npm i -D --save [email protected]

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.

like image 1
iggirex Avatar answered Nov 16 '22 11:11

iggirex