无法加载插件@typescript-eslint:找不到模块“eslint-plugin-@typescript-eslint”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/54514989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:47:26  来源:igfitidea点击:

Failed to load plugin @typescript-eslint: Cannot find module 'eslint-plugin-@typescript-eslint'

typescriptwebpackeslinteslintrceslint-loader

提问by Thilak Rao

I am reconfiguring my project from tslint to eslint. I can run eslint manually, but webpack fails to run with this error message:

我正在将我的项目从 tslint 重新配置为 eslint。我可以手动运行 eslint,但 webpack 无法运行并显示以下错误消息:

Module build failed (from /path/node_modules/eslint-loader/index.js):
Error: Failed to load plugin @typescript-eslint: Cannot find module 'eslint-plugin-@typescript-eslint'

I have ruled out bad .eslintrc.js and missing dependencies since it works when I run it manually ./node_modules/eslint/bin/eslint.js ./ --ext .ts,.tsx --config ./.eslintrc.js

我已经排除了错误的 .eslintrc.js 和缺少的依赖项,因为它在我手动运行时可以工作 ./node_modules/eslint/bin/eslint.js ./ --ext .ts,.tsx --config ./.eslintrc.js

I'm not sure if this is an upstream issue with eslint-loader.

我不确定这是否是 eslint-loader 的上游问题。

module.exports = {
  parser: "@typescript-eslint/parser",
  plugins: ["@typescript-eslint"],
  extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:react/recommended", "plugin:jest/recommended", "prettier", "prettier/@typescript-eslint"],
  rules: {
    "react/prop-types": false
  },
  parserOptions: {
    ecmaVersion: 6,
    project: "./tsconfig.json",
    sourceType: "module"
  },
  settings: {
    react: {
      version: "detect"
    },
    linkComponents: [
      {"name": "Link", "linkAttribute": "href"}
    ]
  },
  env: {
    browser: true
  }
};

My package.json

我的 package.json

{
    "dependencies": {
        "@emotion/core": "10.0.6",
        "facepaint": "1.2.1",
        "react": "16.7.0",
        "react-dom": "16.7.0",
        "react-redux": "6.0.0",
        "redux": "4.0.1",
        "tslib": "1.9.3"
    },
    "devDependencies": {
        "@types/node": "10.12.21",
        "@types/react": "16.8.1",
        "@types/react-dom": "16.0.11",
        "@types/react-redux": "7.0.1",
        "@typescript-eslint/eslint-plugin": "1.2.0",
        "eslint": "5.13.0",
        "eslint-config-prettier": "4.0.0",
        "eslint-plugin-jest": "22.2.2",
        "eslint-plugin-react": "7.12.4",
        "tsconfig-paths-webpack-plugin": "3.2.0",
        "typescript": "3.2.1"
    }
}

回答by krulik

You need to upgrade your eslint version, in the error you can see a bad prefix eslint-plugin-due to some const in eslint/lib/config/plugins.jswhich was removed in later versions.

你需要升级你的 eslint 版本,在错误中你可以看到一个错误的前缀,eslint-plugin-因为一些常量eslint/lib/config/plugins.js在以后的版本中被删除了。

回答by Jeff Tian

I fixed this error by replacing all the ^ to empty in the package.json, and then npm i.

我通过将 , 中的所有 ^ 替换为空package.json,然后将npm i.

enter image description here

在此处输入图片说明