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

Created on 9 Aug 2019  ยท  21Comments  ยท  Source: babel/babel-eslint

eslint and babel-eslint latest versions installed globally

image

.eslintrc in the project folder:
image

But i have the error:
[Error - 11:48:36] ESLint stack trace:
[Error - 11:48:36] Error: Failed to load parser 'babel-eslint' declared in '.eslintrc': Cannot find module 'babel-eslint'
Require stack:

  • E:\webProjects\learning-templates\javascript-async-samples.eslintrc
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:584:15)
    at Function.resolve (internal/modules/cjs/helpers.js:30:19)
    at Object.resolve (C:\Users\fomen\AppData\Roaming\npm\node_modules\eslint\libshared\relative-module-resolver.js:44:50)
    at ConfigArrayFactory._loadParser (C:\Users\fomen\AppData\Roaming\npm\node_modules\eslint\lib\cli-engine\config-array-factory.js:752:45)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (C:\Users\fomen\AppData\Roaming\npm\node_modules\eslint\lib\cli-engine\config-array-factory.js:550:32)
    at _normalizeObjectConfigDataBody.next ()
    at ConfigArrayFactory._normalizeObjectConfigData (C:\Users\fomen\AppData\Roaming\npm\node_modules\eslint\lib\cli-engine\config-array-factory.js:491:20)
    at _normalizeObjectConfigData.next ()
    at createConfigArray (C:\Users\fomen\AppData\Roaming\npm\node_modules\eslint\lib\cli-engine\config-array-factory.js:307:25)
    at ConfigArrayFactory.loadInDirectory (C:\Users\fomen\AppData\Roaming\npm\node_modules\eslint\lib\cli-engine\config-array-factory.js:400:16)

What am I doing wrong?
Previously, this configuration worked.
Stopped working after updating global plugins.

Most helpful comment

What I did is run command: locate babel-eslint in the Terminal. (I'm using Ubuntu)
I got many lines in output, from which I found common path for babel-eslint is: /usr/local/lib/node_modules/babel-eslint
What I did is replace this line in .eslintrc

"parser": "babel-eslint",

with

"parser": "/usr/local/lib/node_modules/babel-eslint",

and that's it, it's working for me. ๐Ÿ˜‰

All 21 comments

I'm seeing the same error. Not sure if same cause, but nearly identical symptoms.

Error: Failed to load parser 'babel-eslint' declared in 'PersonalConfig': Cannot find module 'babel-eslint'
Require stack:
- /Users/Ken/.eslintrc.json
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
    at Function.resolve (internal/modules/cjs/helpers.js:30:19)
    at Object.resolve (/Users/Ken/www/Jost/node_modules/eslint/lib/shared/relative-module-resolver.js:44:50)
    at ConfigArrayFactory._loadParser (/Users/Ken/www/Jost/node_modules/eslint/lib/cli-engine/config-array-factory.js:752:45)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/Users/Ken/www/Jost/node_modules/eslint/lib/cli-engine/config-array-factory.js:550:32)
    at _normalizeObjectConfigDataBody.next (<anonymous>)
    at ConfigArrayFactory._normalizeObjectConfigData (/Users/Ken/www/Jost/node_modules/eslint/lib/cli-engine/config-array-factory.js:491:20)
    at _normalizeObjectConfigData.next (<anonymous>)
    at createConfigArray (/Users/Ken/www/Jost/node_modules/eslint/lib/cli-engine/config-array-factory.js:307:25)
    at ConfigArrayFactory.loadInDirectory (/Users/Ken/www/Jost/node_modules/eslint/lib/cli-engine/config-array-factory.js:400:16)

My .eslintrc.json is as follows:

{
    "env": {
        "browser": true,
        "commonjs": true,
        "es6": true,
        "node": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:react/recommended"
    ],
    "parser": "babel-eslint",
    "parserOptions": {
        "ecmaFeatures": {
            "experimentalObjectRestSpread": true,
            "jsx": true,
            "legacyDecorators": true
        },
        "sourceType": "module",
        "allowImportExportEverywhere": false
    },
    "plugins": [
        "react"
    ],
    "rules": {
        "indent": [
            "off",
            4
        ],
        "linebreak-style": [
            "warn",
            "unix"
        ],
        "no-console": "off",
        "no-mixed-spaces-and-tabs": "warn",
        "no-unused-vars": "off",
        "react/prop-types": ["warn", {"skipUndeclared": true}],
        "quotes": [
            "off",
            "single"
        ],
        "semi": [
            "off",
            "always"
        ]
    }
}

% npm ls -g --depth=0    
/usr/local/lib
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ””โ”€โ”€ [email protected]

% echo $PATH
/usr/local/heroku/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Previously, this worked just fine. I return a day later to this error.

What am I doing wrong?

Encountering the same

Same problem, but my case is about Yarn on Windows.

This clearly stated that babel-eslint is installed globally.

ฮป cat %APPDATA%/../Local/Yarn/Data/global/package.json # "yarn global list" is broken
{
  "dependencies": {
    "babel-eslint": "^10.0.2",
    "dmhy-subscribe": "^0.6.25",
    "eslint": "^6.2.0",
    "firebase-tools": "^7.2.2",
    "httpsrv": "^0.3.0",
    "lighthouse": "^5.2.0",
    "ts-node": "^8.3.0",
    "typescript": "^3.5.3",
    "windows-build-tools": "^5.2.2"
  }
}

Error message:

Error: Failed to load parser 'babel-eslint' declared in '.eslintrc': Cannot find module 'babel-eslint'
Require stack:
- C:\Users\maple3142\Documents\GitHub\browser-extensions\.eslintrc
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:584:15)
    at Function.resolve (internal/modules/cjs/helpers.js:30:19)
    at Object.resolve (C:\Users\maple3142\AppData\Local\Yarn\Data\global\node_modules\eslint\lib\shared\relative-module-resolver.js:44:50)
    at ConfigArrayFactory._loadParser (C:\Users\maple3142\AppData\Local\Yarn\Data\global\node_modules\eslint\lib\cli-engine\config-array-factory.js:754:45)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (C:\Users\maple3142\AppData\Local\Yarn\Data\global\node_modules\eslint\lib\cli-engine\config-array-factory.js:551:32)
    at _normalizeObjectConfigDataBody.next (<anonymous>)
    at ConfigArrayFactory._normalizeObjectConfigData (C:\Users\maple3142\AppData\Local\Yarn\Data\global\node_modules\eslint\lib\cli-engine\config-array-factory.js:491:20)
    at _normalizeObjectConfigData.next (<anonymous>)
    at createConfigArray (C:\Users\maple3142\AppData\Local\Yarn\Data\global\node_modules\eslint\lib\cli-engine\config-array-factory.js:307:25)
    at ConfigArrayFactory.loadInDirectory (C:\Users\maple3142\AppData\Local\Yarn\Data\global\node_modules\eslint\lib\cli-engine\config-array-factory.js:400:16)

.eslintrc:

{
    "parser": "babel-eslint",
    "parserOptions": {
        "ecmaVersion": 8
    },
    "env": {
        "browser": true,
        "node": true,
        "es6": true,
        "worker": true,
        "mocha": true
    },
    "rules": {
        "semi": [
            "error",
            "never"
        ],
        "quotes": [
            "error",
            "single",
            {
                "allowTemplateLiterals": true
            }
        ],
        "max-len": [
            "error",
            {
                "code": 120
            }
        ]
    }
}

It is not recommended to install eslint globally, and plugins must be installed locally:

It is also possible to install ESLint globally rather than locally (using npm install eslint --global). However, this is not recommended, and any plugins or shareable configs that you use must be installed locally in either case.

https://eslint.org/docs/user-guide/getting-started#installation-and-usage

@golopot But it is needed to install eslint global to make vscode-eslint plugin to work everywhere.

Encountering the same issue with [email protected] and [email protected] in a configuration that used to work. Broke after executing yarn upgrade --latest ([email protected]). Running

yarn add babel-eslint -D

solved the issue for me even though babel-eslint was definitely already installed.

Anyone else with a workaround? Using eslint 6.4.0 and babel-eslint 10.0.3

@ronnyfm I installed eslint and babel-eslint to my top level "projects" directory, which while ugly, got the job done.

This still isn't ideal, as if it attempts to use my ~/.eslintrc file it can't find babel-eslint. Linking the file to the projects directory solves this but as before, is messy.

Looks like those two versions of eslint and babel-eslint aren't compatible. It works for me after uninstalling them and install the compatible versions like npm install [email protected] babel-eslint@8 - g

Having the same hassle here. Why do I even need "babel" - I'm not transpiling and just want to lint...

I discovered a sneaky .eslintrc in a parent directory (above my actual application) which I did not create and did not know about. I suspect it was created by the ESLint plugin for VSCode. Deleting this file has solved the issue.

strangely the file /user/userName/.eslintrc contains the followings
{ "parser": "babel-eslint" }
I removed it and it worked just fine

Removing .eslintrc from my top level directory didn't help. To me, eslint should be able to use the babel-eslint relative from where npm was executed even if linting files in other directories. I do not want to install these plugins at the top level.

@ronnyfm it um. does though. that's exactly the behavior is it looks for a local installation of babel-eslint whether it's run locally or globally, using the same mechanics as require('babel-eslint'). So you either gotta install it to every project, or at the top level. The .eslintrc must also be located in a place such that calling require('babel-eslint') would be succesful.

As mentioned by @oiwomark โ€” solved on my end with downgrading eslint to v4.x:

npm -g i eslint@4

@golopot is there any solution for VSCode (i.e. using babel-eslint installed globally)? Despite installing it in the project directory with --save-dev it still shows error...

image

@chojrak11 you'll need to install babel-eslint to a place where your .eslintrc can find it. Since it's in your home directory, you'd have to install it to C:\Users\

Alternatively, copying your .eslintrc to your project directory might work as well, as it'll be able to resolve it to the project-installed copy of babel-eslint

What I did is run command: locate babel-eslint in the Terminal. (I'm using Ubuntu)
I got many lines in output, from which I found common path for babel-eslint is: /usr/local/lib/node_modules/babel-eslint
What I did is replace this line in .eslintrc

"parser": "babel-eslint",

with

"parser": "/usr/local/lib/node_modules/babel-eslint",

and that's it, it's working for me. ๐Ÿ˜‰

This issue is regarding eslint not able to find babel-eslint package. But if you try to install it manually it will fix the issue but will throw error when you do npm start. You have to install the compatible version of babel-eslint for that.
This worked for me ...

  • install babel-eslint manually using npm i -D babel-eslint
  • start your react project using npm-start
  • see the error it shows regarding the version create-react-app uses for babel-eslint
  • install the same version as the one installed by cra tool.

Thank you for the PR. Now that @babel/eslint-parser has been released, we are making this repository read-only. If this is a change you would still like to advocate for, please reopen this in the babel/babel monorepo.

Was this page helpful?
0 / 5 - 0 ratings