[英]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.