[英]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'
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.