简体   繁体   English

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

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

Trying to install eslint into yarn create next-app , but get next error when running linter:尝试将eslint安装到yarn create next-app中,但运行 linter 时出现下一个错误:

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”

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:这是我的.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']

And package.json filepackage.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"
  }

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:第二种选择:在您的.eslintrc文件更改中只需删除您的解析器:

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

Third option: change your parser your node modules package:第三个选项:更改您的解析器您的节点模块 package:

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

install also babel/core:还安装 babel/core:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:无法加载在“.eslintrc”中声明的解析器“babel-eslint”:在 create-react-app 中找不到模块“babel-eslint” - Error: Failed to load parser 'babel-eslint' declared in '.eslintrc': Cannot find module 'babel-eslint' in create-react-app 无法加载在 'package.json » eslint-config-react-app#overrides[0]' 中声明的解析器 '@typescript-eslint/parser':找不到模块 'typescript' - Failed to load parser '@typescript-eslint/parser' declared in 'package.json » eslint-config-react-app#overrides[0]': Cannot find module 'typescript' Eslint - 无法加载解析器 @babel/eslint - Eslint - Failed to load parser @babel/eslint 无法加载在“package.json » eslint-config-react-app”中声明的插件“import”:找不到模块“typescript/package.json” - Failed to load plugin 'import' declared in 'package.json » eslint-config-react-app': Cannot find module 'typescript/package.json' 处理“无法加载在‘.eslintrc’中声明的插件‘react’:找不到模块‘eslint-plugin-react’”ESLint 错误 - Dealing with "Failed to load plugin 'react' declared in '.eslintrc': Cannot find module 'eslint-plugin-react'" ESLint error 无法加载在“.eslintrc.json”中声明的插件“prettier”:找不到模块“eslint-plugin-prettier” - Failed to load plugin 'prettier' declared in '.eslintrc.json': Cannot find module 'eslint-plugin-prettier' ReactJS:无法加载在“package.json”中声明的插件“testing-library”:找不到模块“./eslint-utils” - ReactJS : Failed to load plugin 'testing-library' declared in 'package.json : Cannot find module './eslint-utils' 属性“parser”是错误的类型(预期为 string/null 但得到了 `["@babel/eslint-parser"]`) - Property "parser" is the wrong type (expected string/null but got `["@babel/eslint-parser"]`) 无法加载在“package.json » eslint-config-react-app”中声明的插件“flowtype”:找不到模块“eslint/use-at-your-own-risk” - Failed to load plugin 'flowtype' declared in 'package.json » eslint-config-react-app': Cannot find module 'eslint/use-at-your-own-risk' 解析错误:已为 @typescript-eslint/parser 设置“parserOptions.project”。 该文件与您的项目配置不匹配:.eslintrc.js - Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. The file does not match your project config: .eslintrc.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM