简体   繁体   English

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

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

Since I reinstalled my NPM dependencies in my create-react-app project, Atom's eslint gives me this error on the top of every file:由于我在我的 create-react-app 项目中重新安装了我的 NPM 依赖项,因此 Atom 的 eslint 在每个文件的顶部都给了我这个错误:

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

While react-scripts 's eslint doesn't raise any warning or error.虽然react-scripts的 eslint 不会引发任何警告或错误。 By the way, the package eslint-config-react-app is installed in node_modules .顺便说一句,package eslint-config-react-app安装node_modules中。 I tried to reinstall linter-eslint, atom, the NPM dependencies, etc. Nothing worked.我尝试重新安装 linter-eslint、atom、NPM 依赖项等。没有任何效果。

Has anyone an idea?有人有想法吗?

Here is my.eslintrc:这是我的.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: "^_$"
    }]
  }
}

Edit: I don't know why, but all of the sudden, the error changed and now it's this one on top of every js file:编辑:我不知道为什么,但突然之间,错误发生了变化,现在它是每个 js 文件顶部的错误:

Error while running ESLint: Invalid regular expression flags

EDIT 2编辑 2

None of the given solutions worked in my case.给定的解决方案都不适用于我的情况。 The problem with linter-eslint is not solved. linter-eslint的问题没有解决。 But I found a workaround for now: using fast-eslint instead of linter-eslint .但我现在找到了一种解决方法:使用fast-eslint而不是linter-eslint Works just fine.工作得很好。

For anyone else trying this, one solution is installing eslint-config-react-app globally, along with all of its peer deps.对于尝试此操作的其他人,一种解决方案是全局安装 eslint-config-react-app 及其所有对等部门。 At the moment, that's:此刻,就是:

Refer to https://github.com/facebook/create-react-app/issues/3633#issuecomment-361485857参考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

Since you mentioned that the problem occurred after you reinstalled npm modules, it might be related to npm dependency resolution.由于您提到问题是在您重新安装 npm 模块后出现的,它可能与 npm 依赖解析有关。 So you might have multiple versions of the same module and atom might use the wrong one.因此,您可能有同一个模块的多个版本,而 atom 可能会使用错误的版本。

  1. Check whether your react-scripts version is 0.2.0 or higher according to Displaying Lint Output in the Editor根据Displaying Lint Output in the Editor检查您的 react-scripts 版本是否为 0.2.0 或更高

  2. Remove all eslint related dependencies from your package.json .从 package.json 中删除所有与eslint相关的依赖package.json

    This means removing babel-eslint , eslint , eslint-plugin-flowtype , eslint-plugin-import , eslint-plugin-jsx-a11y , eslint-plugin-react , etc这意味着删除babel-eslinteslinteslint-plugin-flowtypeeslint-plugin-importeslint-plugin-jsx-a11yeslint-plugin-react

    Create react app installs all the linting dependencies under the hood so you shouldn't manually install them. Create react app 会在后台安装所有 linting 依赖项,因此您不应手动安装它们。

  3. Remove all global eslint related dependencies.删除所有与全局eslint相关的依赖项。

    Generally you don't need to use globally installed eslint dependencies as you might have different eslint versions in each of your projects.通常,您不需要使用全局安装的 eslint 依赖项,因为您的每个项目中可能有不同的 eslint 版本。

The latest version of linter-eslint should then use the correct eslint dependencies from under node_modules in your project.然后,最新版本的linter-eslint应该使用项目中 node_modules 下的正确node_modules依赖项。

UPDATE : Based on your comments and edited question, I tried reproducing this using CRA, replacing the dependencies in package.json , reinstalling and adding the following .eslintrc .更新:根据您的评论和编辑的问题,我尝试使用 CRA 重现此内容,替换package.json中的依赖项,重新安装并添加以下.eslintrc

Notice I added " around the options keys in the "no-unused-vars" .请注意,我在"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": "^_$"
    }]
  }
}

Having done all this I couldn't reproduce the issue.完成所有这些后,我无法重现该问题。

暂无
暂无

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

相关问题 (ESLint)在VS 2017 react项目中找不到模块&#39;eslint-config-react-app&#39; - (ESLint) Cannot find module 'eslint-config-react-app' in VS 2017 react project 无法加载在“package.json » eslint-config-react-app”中声明的插件“flowtype”:找不到模块“eslint/use-at-your-own-risk” - Failed to load plugin 'flowtype' declared in 'package.json » eslint-config-react-app': Cannot find module 'eslint/use-at-your-own-risk' eslint-config-react-app 无效 属性“覆盖”是错误的类型 - eslint-config-react-app is invalid Property “overrides” is the wrong type create-react-app 版本 5 的“eslint-config-react-app”问题 - "eslint-config-react-app" issue with create-react-app version 5 插件“react”在“package.json » eslint-config-react-app 之间发生冲突 - Plugin "react" was conflicted between "package.json » eslint-config-react-app eslint-config-react-app throws找不到规则“ getter-return”的定义 - eslint-config-react-app throws Definition for rule 'getter-return' was not found ESLint 错误 - ESLint 找不到配置“react-app” - ESLint error - ESLint couldn't find the config "react-app" 部署 React 应用程序时出错,它一直在说 &lt;&lt; Plugin "react" was conflicted between "package.json » eslint-config-react-app » &gt;&gt; - Error when deploying react app and it keeps sayings << Plugin "react" was conflicted between "package.json » eslint-config-react-app » >> 无法加载在 'package.json » eslint-config-react-app#overrides[0]' 中声明的解析器 '@typescript-eslint/parser':找不到模块 'typescript' - Failed to load parser '@typescript-eslint/parser' declared in 'package.json » eslint-config-react-app#overrides[0]': Cannot find module 'typescript' 如何在Atom编辑器上为React配置ESLint - How to config ESLint for React on Atom Editor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM