【问题标题】:Failed to load plugin 'react' declared in '.eslintrc.json': Cannot find module 'eslint-plugin-react'无法加载在“.eslintrc.json”中声明的插件“react”:找不到模块“eslint-plugin-react”
【发布时间】:2020-07-08 11:19:47
【问题描述】:

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

编辑:删除 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": {
    ...
    }
  }
}

【问题讨论】:

  • 为什么要使用npx 进行lint?包文件和安装步骤说什么,那些插件安装了吗?
  • 我读到它旨在运行依赖项的本地版本而不是全局版本。对吗?
  • 如果它本地安装的,直接调用"lint": "eslint ..."也可以。
  • 它现在给了我一个不同的错误:i.imgur.com/eJJbu2F.png。我已关注并安装但无济于事
  • 请在问题中输入minimal reproducible example。截图没用。

标签: npm continuous-integration eslint bitbucket-pipelines


【解决方案1】:

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

我无意中使用了 2 岁的版本。

【讨论】:

    【解决方案2】:

    通过删除管道的 .env 中的 NODE_ENV 来修复它:

    npm install(在包目录中,无参数):

    在本地 node_modules 文件夹中安装依赖项。

    在全局模式下(即,将 -g 或 --global 附加到命令中),它 安装当前包上下文(即当前工作 目录)作为全局包。

    默认情况下,npm install 将安装列出的所有模块 package.json 中的依赖项。

    使用 --production 标志(或当 NODE_ENV 环境变量 设置为生产),npm 将不会安装列出的模块 devDependencies。

    注意: --production 标志在添加 对项目的依赖。

    【讨论】:

    【解决方案3】:

    碰巧发生了。

    努力寻找答案。

    显然,eslint 在工作目录中搜索根目录,或类似的东西,以找到要导入的模块。

    碰巧我的项目文件夹中有两个应用程序,只有一个有 eslintrc.josn。

    我固定在整个项目上使用 eslint 打开 vs settings.json 并添加以下内容:

    "eslint.workingDirectories": ["./app1","./app2"...]

    如果您的项目文件夹中有多个应用程序,您应该尝试一下

    【讨论】:

      猜你喜欢
      • 2021-03-31
      • 1970-01-01
      • 1970-01-01
      • 2020-02-12
      • 2019-06-28
      • 2022-01-20
      • 1970-01-01
      • 2021-03-11
      • 1970-01-01
      相关资源
      最近更新 更多