Javascript: Cannot find module 'eslint-plugin-import'

Created on 30 Nov 2019  路  24Comments  路  Source: airbnb/javascript

I've been encountering this issue while trying to setup eslint with airbnb. Using this npx package.
https://www.npmjs.com/package/eslint-config-airbnb-base

ESlint output

Failed to load plugin 'import' declared in 'server\.eslintrc.js 禄 eslint-config-airbnb-base 禄 Z:\Development\JS\Nuxt-Test-App\zuka-ma-shlong\server\node_modules\eslint-config-airbnb-base\rules\imports.js': Cannot find module 'eslint-plugin-import'

package.json

{
  "name": "server",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cors": "^2.8.5",
    "eslint": "6.1.0",
    "eslint-config-airbnb-base": "14.0.0",
    "eslint-plugin-import": "^2.18.2",
    "express": "^4.17.1"
  }
}

.eslintrc.js

module.exports = {
  env: {
    browser: true,
    commonjs: true,
    es6: true,
    node: true,
  },
  extends: [
    'airbnb-base',
  ],
  globals: {
    Atomics: 'readonly',
    SharedArrayBuffer: 'readonly',
  },
  parserOptions: {
    ecmaVersion: 2018,
  },
  rules: {
  },
};

eslint-plugin-import is however installed locally aswell as eslint.

I've attempted installing the package with yarn which also didn't seem to work either. Issue link

At this point I've ran out of ideas to get this working.

needs eslint rule changaddition

Most helpful comment

I was using eslint outside of the root directory of the project where eslint was placed/installed.
Thank you for following up.

All 24 comments

How are you running eslint?

locally ./node_modules/.bin/eslint
I also have the eslint plugin installed.

Does npm ls exit successfully?

yes.

What version of node and npm?

v10.16.3 Nodejs
6.9.0 NPM

I'm pretty confused; that should work fine. You can try npm install -g [email protected], but i doubt that will make a difference.

mmmm yeah same I'll give it a crack.

Nope didn't work.
Proof eslint import is installed.
image

Seems like an issue worth filing on eslint itself, then.

I wonder if it's only me having this issue.

I've now also tried the latest verison of npm (6.13.1) it also doesn't work.

6.13 is broken on WSL; i'd try 6.12 explicitly.

Yeah tried it before and it didn't work either sadly.

no problem :)

The problem could be: eslint compatibility issues between eslint and eslint-config-airbnb-base

I downgraded to the latest eslint verson 5 through npm i eslint@^5 and it worked for me.

Hope it helps.

I was using eslint outside of the root directory of the project where eslint was placed/installed.
Thank you for following up.

@Rotinx I seem to have the same issue as you; can you please expand on your solution and what you meant by "was used outside the root directory"?

Hey @joelb01-github, unfortunately I can not entirely recall. I realise now looking back my explanation is terrible sorry about that. I believe it was due to me having ealint installed twice within the same directory.

/ (Installed here)
/Frontend (also installed here)

Though I'm not sure if that's the solution sorry. I would throw the project your having a issue with into a separate folder outside of the root project folder to test if it works outside of it.

@Rotinx thanks for coming back to me :)

I ended up making it work; in my case my .eslintrc had a wrong syntax - the error was quite misleading tho..

@joelb01-github np, I agree it's a bit of a pain.

Hey @joelb01-github, unfortunately I can not entirely recall. I realise now looking back my explanation is terrible sorry about that. I believe it was due to me having ealint installed twice within the same directory.

/ (Installed here)
/Frontend (also installed here)

Though I'm not sure if that's the solution sorry. I would throw the project your having a issue with into a separate folder outside of the root project folder to test if it works outside of it.

I was able to get my eslint working in visual studio code by opening the subfolder where my node_modules reside,

My project structure is:
-Main Folder
-->api
-->auth
-->db
-->ui (npm folder with eslint etc)

So opened the ui folder and it loaded.

@joelb01-github thank you!! Wrestled with this for quite some time. Cleaning out my ESLint config finally resolved it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tpiros picture tpiros  路  3Comments

stephenkingsley picture stephenkingsley  路  3Comments

felixsanz picture felixsanz  路  3Comments

ar
mbifulco picture mbifulco  路  3Comments

surfaceowl picture surfaceowl  路  3Comments