简体   繁体   中英

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.

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.

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.

Also, be sure, that you have latest version of "eslint-plugin-import" plugin, as in my case, for example i had this error with "2.20.1" version, but latest "2.25.3" solved this issue

In my case, i was not using jest at all.

So i had to downgrade de eslint dev dependency:

"eslint": "^7.32.0",

as it say here: https://github.com/eslint/eslint/issues/15149#issuecomment-939501275

I had the same error caused by the eslint-plugin-import dependency and in my case, I got rid of the error by increasing to the latest version of the package.

For those having the following error with flutter firebase cloud functions after running firebase init functions and trying to run firebase deploy --only functions :

ESLint: 8.9.0
 
Error: Failed to load plugin 'import' declared in '.eslintrc.js': Cannot find module 'es-abstract/2021/RequireObjectCoercible'
Require stack:
- C:\Users\xx\Documents\xx\xx\functions\node_modules\eslint-plugin-import\lib\ExportMap.js
- C:\Users\xx\Documents\xx\xx\functions\node_modules\eslint-plugin-import\lib\rules\named.js
- C:\Users\xx\Documents\xx\xx\functions\node_modules\eslint-plugin-import\lib\index.js
- C:\Users\xx\Documents\xx\xx\functions\node_modules\@eslint\eslintrc\dist\eslintrc.cjs

This was solved by:

  • delete node_modules in functions folder
  • delete package-lock.json in functions folder
  • cd.\functions\ in the terminal to get into functions folder, run npm i , cd../
  • firebase deploy --only functions

I am having this issue too which was why I checked this post but did not see any answer that work for me. After searching online, I stumbled into this code which solves my problem.

 npm i -D eslint @typescript-eslint/eslint-plugin

I hope this will help you too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM