【问题标题】:Error: Failed to load parser '@babel/eslint-parser' declared in '.eslintrc.js': Cannot find module '@babel/core/package.json'错误:无法加载在“.eslintrc.js”中声明的解析器“@babel/eslint-parser”:找不到模块“@babel/core/package.json”
【发布时间】:2022-01-14 10:54:27
【问题描述】:

尝试将eslint 安装到yarn create next-app,但运行 linter 时出现下一个错误:

错误:无法加载在“.eslintrc.js”中声明的解析器“@babel/eslint-parser”:找不到模块“@babel/core/package.json”

详情:

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.

这是我的.eslintrc.js 配置文件:

    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']

还有package.json文件

"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"
  }

【问题讨论】:

    标签: reactjs next.js babeljs eslint


    【解决方案1】:

    我以前遇到过这个问题。让我帮你做一些你可以尝试的事情。

    第一个选项:

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

    第二个选项: 在您的 .eslintrc 文件更改中只需删除您的解析器:

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

    第三个选项: 更改您的解析器您的节点模块包:

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

    【讨论】:

    • 谢谢,但您的回答无效。
    猜你喜欢
    • 1970-01-01
    • 2022-06-23
    • 2020-12-08
    • 1970-01-01
    • 1970-01-01
    • 2020-02-02
    • 2021-10-03
    • 2021-09-10
    • 2020-01-01
    相关资源
    最近更新 更多