首页 > 解决方案 > 无法加载在“.eslintrc.json”中声明的插件“react”:找不到模块“eslint-plugin-react”

问题描述

在本地运行时,它似乎工作正常,但在管道上运行时崩溃

在此处输入图像描述

编辑:删除 npx 后,它会产生不同的错误:

在此处输入图像描述

我已遵循安装插件的建议:

npm install eslint-plugin-react@latest --save-dev

但渗出重演。

这是我收回的 bitbucket-pipelines.yml 配置:

  - step:
          name: CI
          caches:
              - node
          script:
              - npm install
              - npm run lint
              - npm run test

等同于 package.json

    "lint": "eslint --ext .js,.ts,.tsx src --ignore-pattern node_modules/",
    "test": "jest --verbose --colors --coverage",

这是我的 eslint 配置文件:

{
    "env": {
        "browser": true,
        "es6": true,
        "jest": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:react/recommended",
        "airbnb"
    ],
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 2018,
        "sourceType": "module"
    },
    "plugins": [
        "react",
        "@typescript-eslint"
    ],
    "settings": {
      "import/resolver": {
        "node": {
          "extensions": [".js", ".ts", ".tsx"],
          "paths": ["src"]
        }
      }
    },
    "rules": {
    ...
    }
  }
}

标签: npmcontinuous-integrationeslintbitbucket-pipelines

解决方案


Visual Studio Code 的更新为我解决了这个问题。

我在不知不觉中使用了 2 岁的版本。


推荐阅读