Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to load plugin 'import' declared in '... » eslint-config-standard': Cannot find module 'eslint-plugin-import'

I've been trying to use ESLint along with Standard and I haven't been able to get it to work. I've tried setting it up through eslint --init, uninstalling eslint globally and having all the packages locally, installing each package manually npm install --save-dev eslint eslint-config-standard eslint-plugin-standard eslint-plugin-promise eslint-plugin-import eslint-plugin-node, reinstalling ESLint extension and nothing so far. I'm perfectly able to run ./node_modules/.bin/eslint --fix ... in order to fix/check errors but it doesn't work with the VSCode extension by any meanings. I don't have prettier so it isn't related to it either.

Output:

[Info  - 12:33:20 AM] ESLint server is running.
[Info  - 12:33:23 AM] ESLint library loaded from: c:\Users\h08FXplsV8\Documents\dev\node\graphql-bootcamp\graphql-prisma\node_modules\eslint\lib\api.js
[Error - 12:33:25 AM] 
Failed to load plugin 'import' declared in 'graphql-prisma\.eslintrc » eslint-config-standard': Cannot find module 'eslint-plugin-import'
Require stack:
 - C:\Users\h08FXplsV8\Documents\dev\node\graphql-bootcamp\__placeholder__.js
Happened while validating C:\Users\h08FXplsV8\Documents\dev\node\graphql-bootcamp\graphql-prisma\src\resolvers\index.js
This can happen for a couple of reasons:
 - The plugin name is spelled incorrectly in an ESLint configuration file (e.g. .eslintrc).
 - If ESLint is installed globally, then make sure 'eslint-plugin-import' is installed globally as well.
 - If ESLint is installed locally, then 'eslint-plugin-import' isn't installed correctly.

.eslintrc:

{
    "env": {
        "es6": true,
        "node": true
    },
    "extends": [
        "standard"
    ],
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    "parserOptions": {
        "ecmaVersion": 2018,
        "sourceType": "module"
    },
    "rules": {
    }
}

I've seen other questions in SO related to this issue but none of the solutions worked, unfortunately.

like image 837
André Avatar asked Oct 15 '19 23:10

André


People also ask

What does Eslint plugin Import do?

This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, and prevent issues with misspelling of file paths and import names. All the goodness that the ES2015+ static module syntax intends to provide, marked up in your editor.

What is plugin in Eslint?

A plugin is a special eslint npm package, that provides additional rule definitions ( rules ), environments , processors and configs for different configurations of recommended / default rule values. The plugins property in . eslintrc. js is merely a flag to enable a given plugin after installation with npm i .


2 Answers

To fix the dependency tree, try following these steps in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
  2. Delete node_modules in your project folder.
  3. Remove "babel-eslint" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.
like image 162
BinhLe Avatar answered Oct 02 '22 15:10

BinhLe


I had the same issue for many weeks and finally found this thread and comment on Github: https://github.com/microsoft/vscode-eslint/issues/696#issuecomment-542592372

My issue turned out to be related to subdirectories. As soon as I made the project the only open project with an .eslintrc.js file, all of my linting issues went away.

Hopefully this works for you.

like image 27
Mike Stevens Avatar answered Oct 02 '22 16:10

Mike Stevens