簡體   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'

嘗試將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"
  }

我以前遇到過這個問題。 讓我幫你做一些你可以嘗試的事情。

第一個選項:

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

第二種選擇:在您的.eslintrc文件更改中只需刪除您的解析器:

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

第三個選項:更改您的解析器您的節點模塊 package:

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

還安裝 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM