首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误:未能加载“.eslintrc.js”中声明的解析器@babel/eslint-解析器:无法找到模块@babel/core/pacage.json‘

错误:未能加载“.eslintrc.js”中声明的解析器@babel/eslint-解析器:无法找到模块@babel/core/pacage.json‘
EN

Stack Overflow用户
提问于 2021-12-09 15:49:29
回答 2查看 8.6K关注 0票数 9

尝试将埃斯林安装到yarn create next-app中,但在运行linter时获得下一个错误:

错误:未能加载“.eslintrc.js”中声明的解析器@babel/eslint-解析器:无法找到模块@babel/core/pacage.json‘

详细信息:

代码语言:javascript
复制
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配置文件:

代码语言:javascript
复制
    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文件

代码语言:javascript
复制
"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"
  }
EN

回答 2

Stack Overflow用户

发布于 2021-12-15 07:59:29

我以前有过这个问题。让我帮你做几件你可以尝试的事。

第一种选择:

代码语言:javascript
复制
npm remove babel-eslint && npm install --save-dev @babel/core @babel/eslint-parser 

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

代码语言:javascript
复制
"parser": "@babel/eslint-parser " // delete this line

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

代码语言:javascript
复制
"parser": "/usr/local/lib/node_modules/babel-eslint",
票数 4
EN

Stack Overflow用户

发布于 2022-06-08 08:39:57

还安装babel/core:

代码语言:javascript
复制
$ npm install eslint @babel/core @babel/eslint-parser --save-dev
# or
$ yarn add eslint @babel/core @babel/eslint-parser -D
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70292796

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档