终端中的eslint无法找到模块'eslint-config-react-app'

问题描述 投票:11回答:4

我使用create-react-app制作一个反应应用程序。

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

  1. 已安装eslint yarn global add eslint(eslint v4.1.1但也试过v3.19.0,因为反应应用程序使用了那个)
  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)at在加载时解析(/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)在loadFromDisk(/home/user/.config)的applyExtends(/home/user/.config/yarn/global/node_modules/eslint/lib/config/config-file.js:405:28)的Array.reduceRight(native)处/yarn/global/node_modules/eslint/lib/config/config-file.js:556:22)at Object.load(/home/user/.config/yarn/global/node_modules/eslint/lib/config/config- file.js:592:20)在Config.getConfigHierarchy(/ home / user /)的Config.getLocalConfigHierarchy(/home/user/.config/yarn/global/node_modules/eslint/lib/config.js:228:44)。配置/纱/全球/ node_modules / eslint / lib中/ CO nfig.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
4个回答
4
投票

我想如果你添加错误消息(eslint-config-react-app)中提到的模块它应该工作?例如。 yarn add --dev eslint-config-react-app


2
投票

所以我发现你需要在全局安装'全部'的eslint包。因为它不会让你处理全局的eslint和本地包

所以我做的是yarn global add eslint@^3.19.0 eslint-plugin-jsx-a11y@^5.0.,现在它的工作原理:|


0
投票

您的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偶然发现了这个。


0
投票

首先安装此软件包,ESLint和必要的插件。

npm install --save-dev eslint-config-react-app [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]

然后在项目的根文件夹中创建一个名为.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

© www.soinside.com 2019 - 2024. All rights reserved.