繁体   English   中英

Atom & eslint:找不到模块 'eslint-config-react-app'

[英]Atom & eslint: Cannot find module 'eslint-config-react-app'

由于我在我的 create-react-app 项目中重新安装了我的 NPM 依赖项,因此 Atom 的 eslint 在每个文件的顶部都给了我这个错误:

Error while running ESLint: Cannot find module 'eslint-config-react-app'.

虽然react-scripts的 eslint 不会引发任何警告或错误。 顺便说一句,package eslint-config-react-app安装node_modules中。 我尝试重新安装 linter-eslint、atom、NPM 依赖项等。没有任何效果。

有人有想法吗?

这是我的.eslintrc:

{
  "extends": "react-app",
  "rules": {
    "jsx-a11y/anchor-is-valid": 0,
    "react/jsx-no-comment-textnodes": 0,
    "no-unused-vars": ["warn", {
      args: "all",
      ignoreRestSiblings: false,
      argsIgnorePattern: "^_$"
    }]
  }
}

编辑:我不知道为什么,但突然之间,错误发生了变化,现在它是每个 js 文件顶部的错误:

Error while running ESLint: Invalid regular expression flags

编辑 2

给定的解决方案都不适用于我的情况。 linter-eslint的问题没有解决。 但我现在找到了一种解决方法:使用fast-eslint而不是linter-eslint 工作得很好。

对于尝试此操作的其他人,一种解决方案是全局安装 eslint-config-react-app 及其所有对等部门。 此刻,就是:

参考https://github.com/facebook/create-react-app/issues/3633#issuecomment-361485857

npm i -g babel-eslint@^7.2.3 eslint@^4.1.1 eslint-plugin-flowtype@^2.34.1 eslint-plugin-import@^2.6.0 eslint-plugin-jsx-a11y@^5.1.1 eslint-plugin-react@^7.1.0

由于您提到问题是在您重新安装 npm 模块后出现的,它可能与 npm 依赖解析有关。 因此,您可能有同一个模块的多个版本,而 atom 可能会使用错误的版本。

  1. 根据Displaying Lint Output in the Editor检查您的 react-scripts 版本是否为 0.2.0 或更高

  2. 从 package.json 中删除所有与eslint相关的依赖package.json

    这意味着删除babel-eslinteslinteslint-plugin-flowtypeeslint-plugin-importeslint-plugin-jsx-a11yeslint-plugin-react

    Create react app 会在后台安装所有 linting 依赖项,因此您不应手动安装它们。

  3. 删除所有与全局eslint相关的依赖项。

    通常,您不需要使用全局安装的 eslint 依赖项,因为您的每个项目中可能有不同的 eslint 版本。

然后,最新版本的linter-eslint应该使用项目中 node_modules 下的正确node_modules依赖项。

更新:根据您的评论和编辑的问题,我尝试使用 CRA 重现此内容,替换package.json中的依赖项,重新安装并添加以下.eslintrc

请注意,我在"no-unused-vars" "

{
  "extends": "react-app",
  "rules": {
    "jsx-a11y/anchor-is-valid": 0,
    "react/jsx-no-comment-textnodes": 0,
    "no-unused-vars": ["warn", {
      "args": "all",
      "ignoreRestSiblings": false,
      "argsIgnorePattern": "^_$"
    }]
  }
}

完成所有这些后,我无法重现该问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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