简体   繁体   English

Eslint - 无法加载解析器 @babel/eslint

[英]Eslint - Failed to load parser @babel/eslint

I'm trying to set up Eslint and Prettier for my React Project.我正在尝试为我的 React 项目设置 Eslint 和 Prettier。 For this, I choose the Airbnb Rules Set.为此,我选择了 Airbnb 规则集。 Now I am stuck at the integration of Eslint and Prettier in my VS Code.现在我被困在我的 VS Code 中 Eslint 和 Prettier 的集成上。 It already worked but threw me some weird arrows like:它已经奏效了,但给了我一些奇怪的箭头,例如:

Unexpected argument :

When defining Types.定义类型时。

I found searched for a solution and hit installing a Parser.我发现搜索了一个解决方案并点击了安装解析器。 So I tried to install @babel/eslint-parser.所以我尝试安装@babel/eslint-parser。

But after following this guide I'm getting the following error.但是在遵循指南之后,我收到以下错误。

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

As the error implied that @babel/eslint-parser was missing i tried reinstalling with:由于错误暗示 @babel/eslint-parser 丢失,我尝试重新安装:

npm i @babel/eslint-parser @babel/preset-react -D

Now I'm left a little bit clueless.现在我有点不知所措。

This is my.eslintrc.js这是 my.eslintrc.js

module.exports = {
    extends: ["airbnb", "prettier"],
    plugins: ["prettier"],
    parser: "@babel/eslint-parser",
    parserOptions: {
      requireConfigFile: false,
      babelOptions: {
        presets: ["@babel/preset-react"]
      }
    },
    rules: {
      "prettier/prettier": ["error"],
      "react/jsx-filename-extension": ["off"],
      "react/prefer-stateless-function": ["off"],
      "import/extensions": ["off"],
      "import/no-unresolved": ["off"],
      "indent": ["error", 2]
    }
}; 

I found the Solution by myself.我自己找到了解决方案。 For anyone having a similar issue in the Future.对于任何在未来有类似问题的人。 Check your npm packages.检查您的 npm 包。 The different versions of mine were incompatible and that hindered the usage of babel.我的不同版本不兼容,这阻碍了 babel 的使用。

i had the same issue, the package should be installed properly otherwise it does not work as it should, TO FIX IT DO THIS:我有同样的问题,package 应该正确安装,否则它不能正常工作,修复它这样做:

npm install babel-eslint --save-dev

DONT FORGET TO "NPM RUN BUILD" AFTERWARD之后不要忘记“NPM RUN BUILD”

暂无
暂无

声明:本站的技术帖子网页,遵循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 错误:无法加载在“.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:无法加载配置“next/babel”以扩展 - ESLint: Failed to load config "next/babel" to extend from 创建反应应用程序 - 没有打字稿,得到错误:无法加载解析器'@typescript-eslint/parser' - create react app - without typescript , got Error: Failed to load parser '@typescript-eslint/parser' Eslint 在使用 babel 解析器时禁用严格模式 - Eslint disable strict mode when using babel parser 无法加载在 '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' 属性“parser”是错误的类型(预期为 string/null 但得到了 `["@babel/eslint-parser"]`) - Property "parser" is the wrong type (expected string/null but got `["@babel/eslint-parser"]`) 处理“无法加载在‘.eslintrc’中声明的插件‘react’:找不到模块‘eslint-plugin-react’”ESLint 错误 - Dealing with "Failed to load plugin 'react' declared in '.eslintrc': Cannot find module 'eslint-plugin-react'" ESLint error babel-eslint vs eslint-plugin-babel vs eslint-plugin-react? - babel-eslint vs eslint-plugin-babel vs eslint-plugin-react? 无法加载要扩展的配置“@ljharb”。 (ESLint 8,网页包 5) - Failed to load config "@ljharb" to extend from. (ESLint 8, Webpack 5)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM