首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ESLint找不到插件"eslint- plugin -@typescript-eslint“

ESLint找不到插件"eslint- plugin -@typescript-eslint“
EN

Stack Overflow用户
提问于 2019-03-08 09:28:33
回答 9查看 34K关注 0票数 31

我不确定我正在使用的东西是否有bug,或者我在这里设置了什么错误,但是在运行eslint src --fix时,我从eslint获得了这个错误--关于“eslint@typescript eslint”

我已经将插件指定为@TypeScript-eslint文档中列出的插件,但是在这个奇怪的错误中,eslint试图将‘eslint’添加到插件名的开头(包名是@typescript-eslint/eslint-plugin)。

我正在使用盖茨比和伴随的TypeScript插件

误差

代码语言:javascript
复制
$ eslint src --fix

Oops! Something went wrong! :(

ESLint: 4.19.1.
ESLint couldn't find the plugin "eslint-plugin-@typescript-eslint". This can happen for a couple different reasons:

1. If ESLint is installed globally, then make sure eslint-plugin-@typescript-eslint is also installed globally. A globally-installed ESLint cannot find a locally-installed plugin.

2. If ESLint is installed locally, then it's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

    npm i eslint-plugin-@typescript-eslint@latest --save-dev

.eslintrc.js:

代码语言:javascript
复制
module.exports = {
  parser: '@typescript-eslint/parser',
  parserOptions: {
    ecmaFeatures: {
      jsx: true,
    },
    ecmaVersion: 2018,
    sourceType: 'module',
  },
  env: {
    browser: true,
    node: true,
    es6: true,
    'jest/globals': true,
  },
  plugins: ['@typescript-eslint', 'react', 'jest'],
  extends: [
    'standard',
    'plugin:react/recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:jest/recommended',
    'plugin:prettier/recommended',
    // 'eslint-config-prettier', // must be last
    'prettier/@typescript-eslint',
  ],
  rules: {
    'react/prop-types': 0,
    'jsx-quotes': ['error', 'prefer-single'],
    'react/no-unescaped-entities': 0,
  },
  settings: {
    react: {
      version: 'detect',
    },
    linkComponents: [
      // Components used as alternatives to <a> for linking, eg. <Link to={ url } />
      'Hyperlink',
      { name: 'Link', linkAttribute: 'to' },
    ],
  },
}

package.json

代码语言:javascript
复制
{
  "name": "jmulholland.com",
  "description": "My personal website",
  "license": "MIT",
  "scripts": {
    "dev": "gatsby develop",
    "build": "gatsby build",
    "serve": "gatsby serve",
    "lint": "eslint src --fix",
    "prettier": "prettier \"**/*.+(js|jsx|ts|tsx|json|css|md|mdx|graphql)\"",
    "format": "yarn prettier --write",
    "type-check": "tsc --noEmit",
    "validate": "yarn lint && yarn prettier --list-different"
  },
  "dependencies": {
    "gatsby": "^2.1.4",
    "gatsby-plugin-react-helmet": "^3.0.6",
    "gatsby-plugin-styled-components": "^3.0.5",
    "gatsby-plugin-typescript": "^2.0.10",
    "gatsby-plugin-typography": "^2.2.7",
    "gatsby-remark-prismjs": "^3.2.4",
    "gatsby-source-contentful": "^2.0.29",
    "gatsby-transformer-remark": "^2.3.0",
    "prismjs": "^1.15.0",
    "prop-types": "^15.7.2",
    "react": "^16.8.2",
    "react-dom": "^16.8.2",
    "react-helmet": "^5.2.0",
    "react-typography": "^0.16.18",
    "styled-components": "^4.1.3",
    "typography": "^0.16.18"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^1.4.2",
    "@typescript-eslint/parser": "^1.4.2",
    "babel-jest": "^24.1.0",
    "babel-plugin-styled-components": "^1.10.0",
    "babel-preset-gatsby": "^0.1.8",
    "dotenv": "^6.0.0",
    "eslint": "^4.19.1",
    "eslint-config-prettier": "^4.1.0",
    "eslint-config-standard": "^12.0.0",
    "eslint-plugin-import": "^2.16.0",
    "eslint-plugin-jest": "^22.3.0",
    "eslint-plugin-jsx-a11y": "^6.2.1",
    "eslint-plugin-node": "^8.0.1",
    "eslint-plugin-prettier": "^3.0.1",
    "eslint-plugin-promise": "^4.0.1",
    "eslint-plugin-react": "^7.11.1",
    "eslint-plugin-standard": "^4.0.0",
    "faker": "^4.1.0",
    "husky": "^1.3.1",
    "jest": "^24.1.0",
    "lint-staged": "^8.1.5",
    "prettier": "^1.16.4",
    "typescript": "^3.3.3333"
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  }
}
EN

回答 9

Stack Overflow用户

发布于 2019-03-08 10:33:17

解决方案只是升级到最新版本的eslint。

票数 19
EN

Stack Overflow用户

发布于 2021-07-06 12:39:52

不确定它是否还没有解决。但是,将"root": true添加到我的.eslintrc.json中对我有帮助。

票数 13
EN

Stack Overflow用户

发布于 2021-01-14 15:14:43

对于任何可能面临这个问题的未来读者来说,在我的例子中,我使用的是基于node:alpine映像的多阶段Docker构建。多阶段构建的目的是在应用程序的dependenciesdevDependencies (在package.json中)之间建立一个分离。

在创建Dockerfile时,经过了几个小时的修改,我在Dockerfile的开头添加了下面的一行

代码语言:javascript
复制
ENV NODE_ENV production 

这会导致npm忽略devDependencies包,而这反过来又会导致ESLint失败(因为它没有安装)。

我将环境变量声明移到了我最初想要的最后(版本)构建阶段,然后npm安装了所有必需的包,ESLint成功运行。

希望这能节省一些宝贵的时间。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55060228

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档