26

Trying to install eslint into create-react-app, but get next error when running linter:

enter image description here]

Here is my .eslintrc config file:

{
  "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: enter image description here

Alexandr Tovmach
  • 3,071
  • 1
  • 14
  • 31

12 Answers12

20

Did you install @babel/eslint-parser or eslint-parser? In my case I had to use @babel/eslint-parser and .eslintrc looks like this:

"parser": "@babel/eslint-parser",
Mahdiyeh
  • 865
  • 11
  • 12
  • 3
    As per the npm page of [https://www.npmjs.com/package/babel-eslint](`babel-eslint` ), it is deprecated. See this image on [Imgur](https://i.imgur.com/iqJ0FIm.png) It says `babel-eslint is now @babel/eslint-parser`. So using your suggestion worked for me. Thanks @Mahdiyeh – August May 09 '22 at 14:29
  • 1
    This helped me `https://tjaddison.com/blog/2021/03/updating-babel-eslint-to-babeleslint-parser-for-react-apps/` – smile Aug 12 '22 at 02:19
17

To fix this issue just reuse babel-eslint dependency from react-scripts, that already installed. Update your config:

{
  "extends": ["airbnb", "prettier", "prettier/react"],
  "plugins": ["prettier"],
  "parser": "react-scripts/node_modules/babel-eslint"
}
Alexandr Tovmach
  • 3,071
  • 1
  • 14
  • 31
6

In my case solution was just run npm install eslint --save-dev for update eslint version

Oleg
  • 1,044
  • 1
  • 14
  • 10
3
❯ 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

yarn remove babel-eslint
yarn add -D @babel/eslint-parser
user158
  • 12,852
  • 7
  • 62
  • 94
2

yarn add eslint --save-dev solved that issue for me!

2

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).

So just: yarn add -D babel-eslint

ch271828n
  • 15,854
  • 5
  • 53
  • 88
1

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. As you can see... I had some random .eslintrc living outside of my project which was somehow getting picked up.

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.

Omar
  • 421
  • 4
  • 10
0

Running eslint on your projects root folder eslint . will display the missing packages that you might need to install and that worked well for me.

boomchickawawa
  • 508
  • 1
  • 6
  • 25
0

Just add @babel/eslint-parser in .eslintrc

  • 3
    Thanks for contributing! If you find time please edit an explanation into the answer as it's recommended to [explain code-based answers](https://meta.stackoverflow.com/q/392712/128421) on StackOverflow. – Sven Viking Mar 28 '22 at 10:32
0

As for me i simply install this npm install eslint@4.x babel-eslint@8 - g and it works for me

  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/31671570) – Ethan May 07 '22 at 23:18
0

I have yet another "this is what worked for me" answer. Like others my issue is definitely related to the deprecation of 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. For a while I thought the solution was removing the old eslint-config-react-app, but several iterations later I found I needed the direct dependency.

$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 i eslint-config-react-app

added 1 package, and audited 2909 packages in 6s

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

This works like Charm

npm update eslint

Joe Rush
  • 139
  • 1
  • 4