简体   繁体   English

错误:无法加载在“.eslintrc”中声明的解析器“babel-eslint”:在 create-react-app 中找不到模块“babel-eslint”

[英]Error: Failed to load parser 'babel-eslint' declared in '.eslintrc': Cannot find module 'babel-eslint' in create-react-app

Trying to install eslint into create-react-app , but get next error when running linter:尝试将eslint安装到create-react-app中,但在运行 linter 时出现下一个错误:

在此处输入图像描述]

Here is my .eslintrc config file:这是我的.eslintrc配置文件:

{
  "extends": ["airbnb", "prettier", "prettier/react"],
  "plugins": ["prettier"],
  "parser": "babel-eslint"
}

If install babel-eslint manually it'll potentially produce another error based on package conflict between project and react-scripts dependencies:如果手动安装babel-eslint ,它可能会基于项目和react-scripts依赖项之间的 package 冲突产生另一个错误: 在此处输入图像描述

To fix this issue just reuse babel-eslint dependency from react-scripts , that already installed.要解决此问题,只需重用已安装的react-scripts中的babel-eslint依赖项。 Update your config:更新您的配置:

{
  "extends": ["airbnb", "prettier", "prettier/react"],
  "plugins": ["prettier"],
  "parser": "react-scripts/node_modules/babel-eslint"
}

Did you install @babel/eslint-parser or eslint-parser ?你安装了@babel/eslint-parser还是eslint-parser In my case I had to use @babel/eslint-parser and .eslintrc looks like this:在我的情况下,我不得不使用@babel/eslint-parser.eslintrc看起来像这样:

"parser": "@babel/eslint-parser",

在我的情况下,解决方案只是运行npm install eslint --save-dev来更新 eslint 版本

yarn add eslint --save-dev为我解决了这个问题!

A little late here but thought I would share what got me going...这里有点晚了,但我想我会分享让我前进的原因......

I completely dismissed the error output which tells me where the .eslintrc file (that is looking for said package) lives.我完全忽略了错误输出,它告诉我.eslintrc文件(正在寻找所述包)的位置。 As you can see... I had some random .eslintrc living outside of my project which was somehow getting picked up.正如你所看到的......我有一些随机的.eslintrc生活在我的项目之外,不知何故被捡起。

Failed to load parser 'babel-eslint' declared in '../.eslintrc': Cannot find module 'babel-eslint'

Solution:解决方案:

Deleting this package ended up fixing the error for me.删除这个包最终为我修复了错误。 Not sure how that file got there but by mistake in a previous project.不确定该文件是如何到达那里的,但在以前的项目中是错误的。

I suspect that it has something to do with installing babel-eslint and eslint globally.我怀疑这与全局安装 babel-eslint 和 eslint 有关。

For me, it is because that dependency is really not installed... I just followed the GatsbyJS's official guide, and it is not installed (not sure why that guide is not complete).对我来说,这是因为确实没有安装该依赖项......我只是按照 GatsbyJS 的官方指南,它没有安装(不知道为什么该指南不完整)。

So just: yarn add -D babel-eslint所以只需: yarn add -D babel-eslint

❯ yarn add -D babel-eslint 
yarn add v1.22.15
[1/4] Resolving packages...
warning babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.

babel-eslint seems deprecated and package is now provided as an ES module under babel , so remove babel-eslint and instead install @babel/eslint-parser babel-eslint似乎已弃用,并且包现在作为babel下的 ES 模块提供,因此请删除babel-eslint并安装@babel/eslint-parser

yarn remove babel-eslint
yarn add -D @babel/eslint-parser

Running eslint on your projects root folder eslint .在项目根文件夹 eslint 上运行eslint . will display the missing packages that you might need to install and that worked well for me.将显示您可能需要安装的丢失的软件包,并且对我来说效果很好。

只需在 .eslintrc 中添加@babel/eslint-parser

至于我,我只需安装这个 npm install eslint@4.x babel-eslint@8 - g 它对我有用

I have yet another "this is what worked for me" answer.我还有另一个“这对我有用”的答案。 Like others my issue is definitely related to the deprecation of babel-eslint .像其他人一样,我的问题肯定与babel-eslint的弃用有关。 My specific issue was that eslint-config-react-app was marked as a direct dependency, which I hadn't upgraded as part of upgrading a major version of react-scripts , somehow this left me with a version of eslint-config-react-app that was expecting babel-eslint , but only @babel/eslint-parser installed.我的具体问题是eslint-config-react-app被标记为直接依赖项,我没有在升级react-scripts的主要版本时升级它,不知何故这给我留下了一个eslint-config-react-app版本eslint-config-react-app期待babel-eslint ,但只安装了@babel/eslint-parser Removing eslint-config-react-app only removed the old direct dependency, but left things broken in a different way, reinstalling (without making it a direct dependency of my package) got things working again for me.删除eslint-config-react-app只删除了旧的直接依赖项,但以不同的方式破坏了事情,重新安装(不使其成为我的包的直接依赖项)让事情再次为我工作。 I'm sure there's a cleaner way of doing this.我敢肯定有一种更清洁的方法可以做到这一点。

$npm ls eslint-config-react-app
client@0.1.1 /srv/
├── eslint-config-react-app@6.0.0
└─┬ react-scripts@5.0.1
  └── eslint-config-react-app@7.0.1

$ npm rm eslint-config-react-app

removed 1 package, and audited 2909 packages in 4s

$ npm ls eslint-config-react-app
client@0.1.1 /srv/
└─┬ react-scripts@5.0.1
  └── eslint-config-react-app@7.0.1
$ npm i --no-save eslint-config-react-app

added 1 package, removed 1 package, and audited 2909 packages in 6s

$ npm ls eslint-config-react-app
client@0.1.1 /srv/
└─┬ react-scripts@5.0.1
  └── eslint-config-react-app@7.0.1

This works like Charm这就像魅力

npm update eslint npm 更新 eslint

暂无
暂无

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

相关问题 错误:无法加载在“.eslintrc.js”中声明的解析器“@babel/eslint-parser”:找不到模块“@babel/core/package.json” - Error: Failed to load parser '@babel/eslint-parser' declared in '.eslintrc.js': Cannot find module '@babel/core/package.json' 处理“无法加载在‘.eslintrc’中声明的插件‘react’:找不到模块‘eslint-plugin-react’”ESLint 错误 - Dealing with "Failed to load plugin 'react' declared in '.eslintrc': Cannot find module 'eslint-plugin-react'" ESLint error babel-eslint vs eslint-plugin-babel vs eslint-plugin-react? - babel-eslint vs eslint-plugin-babel vs eslint-plugin-react? “babel-eslint”不能让我安装反应 - "babel-eslint" can't let me install react Eslint - 无法加载解析器 @babel/eslint - Eslint - Failed to load parser @babel/eslint 如何在没有配置文件的情况下修复导入/导出babel-eslint? - How to fix import/export babel-eslint without configuration file? npm start 显示 babel-eslint 版本存在问题 - npm start is showing an issue with babel-eslint version 'yarn start' 抛出 babel-eslint 错误 MacOS,我该如何解决这个错误? - 'yarn start' throws babel-eslint error MacOS, how do I fix this error? 错误:无法加载插件导入:在部署 create-react-app 时找不到模块“eslint-plugin-import” - Error: Failed to load plugin import: Cannot find module 'eslint-plugin-import' when deploying a create-react-app 无法加载在“.eslintrc.json”中声明的插件“prettier”:找不到模块“eslint-plugin-prettier” - Failed to load plugin 'prettier' declared in '.eslintrc.json': Cannot find module 'eslint-plugin-prettier'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM