【问题标题】:eslint in terminal Cannot find module 'eslint-config-react-app'终端中的 eslint 找不到模块“eslint-config-react-app”
【发布时间】:2017-12-01 16:32:54
【问题描述】:

我使用 create-react-app 来制作一个 react 应用。

linter 在 create-react-app 中工作,但现在我想让它在我的 sublimetext 中工作。

  1. 安装了 eslint yarn global add eslint(eslint v4.1.1 但也尝试了 v3.19.0,因为 react 应用程序使用了那个)
  2. 运行eslint --init并配置它
  3. 进入项目目录并创建一个名为.eslintrc的文件
  4. 内部文件:
{
"extends": "react-app"
}
  1. 在项目目录下运行eslint src/App.js
  2. 在终端出现错误:

    引用自:/mnt/storage/Dev/newapp/.eslintrc 错误:找不到模块“eslint-config-react-app”

    引用自:/mnt/storage/Dev/newapp/.eslintrc 在 ModuleResolver.resolve (/home/user/.config/yarn/global/node_modules/eslint/lib/util/module-resolver.js:74:19) 在解决(/home/user/.config/yarn/global/node_modules/eslint/lib/config/config-file.js:515:25) 加载时(/home/user/.config/yarn/global/node_modules/eslint/lib/config/config-file.js:584:26) 在 configExtends.reduceRight (/home/user/.config/yarn/global/node_modules/eslint/lib/config/config-file.js:421:36) 在 Array.reduceRight (本机) 在 applyExtends (/home/user/.config/yarn/global/node_modules/eslint/lib/config/config-file.js:405:28) 在 loadFromDisk (/home/user/.config/yarn/global/node_modules/eslint/lib/config/config-file.js:556:22) 在 Object.load (/home/user/.config/yarn/global/node_modules/eslint/lib/config/config-file.js:592:20) 在 Config.getLocalConfigHierarchy (/home/user/.config/yarn/global/node_modules/eslint/lib/config.js:228:44) 在 Config.getConfigHierarchy (/home/user/.config/yarn/global/node_modules/eslint/lib/config.js:182:43)

我确实添加了yarn global add babel-eslint eslint-plugin-react eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-flowtype。但我认为这已经没有必要了!

【问题讨论】:

    标签: eslint create-react-app yarnpkg sublimelinter


    【解决方案1】:

    我认为如果您添加错误消息 (eslint-config-react-app) 中提到的模块,它应该可以工作吗?例如。 yarn add --dev eslint-config-react-app

    【讨论】:

      【解决方案2】:

      您的package-lock.json 文件中可能存在错误配置,其中删除了 ESLint。我遇到了完全相同的问题并通过以下方式解决了它:

      1. cd <your-project-directory>
      2. rm package-lock.json
      3. rm -rf node_modules
      4. npm install

      您可以运行npm ls eslint --depth=99 来验证eslint 软件包是否已安装。我是通过 GitHub 上的 comment from feross 偶然发现的。

      【讨论】:

        【解决方案3】:

        所以我发现你必须全局安装“所有”eslint 包。因为它不会让你处理全局 eslint 和本地包

        所以我所做的是 yarn global add eslint@^3.19.0 eslint-plugin-jsx-a11y@^5.0. 现在可以了:|

        【讨论】:

          【解决方案4】:

          首先安装这个包,ESLint和必要的插件。

          npm install --save-dev eslint-config-react-app babel-eslint@9.x eslint@5.x eslint-plugin-flowtype@2.x eslint-plugin-import@2.x eslint-plugin-jsx-a11y@6.x eslint-plugin-react@7.x
          

          然后在项目的根文件夹中创建一个名为 .eslintrc.json 的文件,其内容如下:

           {
            "root": true,
            "ecmaFeatures": {
              "jsx": true
            },
            "env": {
              "browser": true,
              "node": true,
              "jquery": true
            },
            "rules": {
              "quotes": 0,
              "no-trailing-spaces": 0,
              "eol-last": 0,
              "no-unused-vars": 0,
              "no-underscore-dangle": 0,
              "no-alert": 0,
              "no-lone-blocks": 0
            },
            "globals": {
              "jQuery": true,
              "$": true
            }
          }
          

          See Reference

          【讨论】:

            【解决方案5】:

            在组织黑客马拉松时,我遇到了这个问题。上述与配置相关的解决方案对我不起作用。

            这最终对我来说是几个错误。

            首先,SublimeText 目前(2021 年 11 月 12 日)与 2021 年 9 月或 2021 年 10 月某处发布的 Eslint v8.0 不兼容。我通过以下操作解决了这个问题:

            # HEADS UP: If your project currently relies on eslint v8.0, then further Sublime Text configuration might be required.
            
            # Global install
            npm uninstall -g eslint
            npm install -g eslint@7
            
            # Local install
            npm uninstall -D eslint
            npm install -D eslint@7
            

            但这还不够。现在需要打字稿,因为我在本地项目上初始化文件时选择了使用打字稿。 (你也可以通过运行eslint --init 来做到这一点)

            所以我必须做以下事情:

            # Local install
            npm install -D typescript
            

            现在工作得很好。

            【讨论】:

              猜你喜欢
              • 2020-02-28
              • 2019-04-19
              • 2017-01-04
              • 2018-11-19
              • 2022-01-07
              • 2022-01-20
              • 1970-01-01
              • 1970-01-01
              • 2017-10-04
              相关资源
              最近更新 更多