10

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

Error: Failed to load parser '@babel/eslint-parser' declared in '.eslintrc.js': Cannot find module '@babel/core/package.json'

Detail:

info  - Loaded env from /project/.env
Error: Failed to load parser '@babel/eslint-parser' declared in '.eslintrc.js': Cannot find module '@babel/core/package.json'
Require stack:
- /project/node_modules/@babel/eslint-parser/lib/parse.cjs
- /project/node_modules/@babel/eslint-parser/lib/index.cjs
- /project/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Here is my .eslintrc.js config file:

    browser: true,
    es2020: true,
    es6: true,
    node: true
  },
  extends: ['airbnb', 'prettier', 'next/core-web-vitals'],
  parser: '@babel/eslint-parser',
  parserOptions: {
    ecmaVersion: 2021,
    requireConfigFile: false
  },
  plugins: ['react']

And package.json file

"devDependencies": {
    "@babel/eslint-parser": "^7.16.3",
    "eslint": "^8.4.1",
    "eslint-config-airbnb": "^19.0.2",
    "eslint-config-next": "^12.0.7",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-import": "^2.25.3",
    "eslint-plugin-jsx-a11y": "^6.5.1",
    "eslint-plugin-react": "^7.27.1",
    "prettier": "^2.5.1"
  }

2 Answers 2

5

I had this problem before. Let me help you with a few things that u can try.

First option:

npm remove babel-eslint && npm install --save-dev @babel/core @babel/eslint-parser 

Second option: in your .eslintrc file change simply remove your parser:

"parser": "@babel/eslint-parser " // delete this line

Third option: change your parser your node modules package:

"parser": "/usr/local/lib/node_modules/babel-eslint",
Sign up to request clarification or add additional context in comments.

1 Comment

I ran into the same issue with Failed to load parser '@typescript-eslint/parser' declared in '.eslintrc.js'. I followed your instructions and they fixed the issue!
4

install also babel/core:

$ npm install eslint @babel/core @babel/eslint-parser --save-dev
# or
$ yarn add eslint @babel/core @babel/eslint-parser -D

1 Comment

npm command worked for me (Ubuntu 22.04 on a dual-boot MBA 2019)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.