eslint - ESLint:解析错误:此实验性语法需要启用以下解析器插件之一:'jsx, flow, typescript' (2:9)
问题描述
我正在尝试在 webstorm 中使用 eslint,但它不起作用并显示错误:ESLint: Parsing error: This Experimental syntax requires enable the following parser plugin(s): 'jsx, flow, typescript' (2: 9)。这是我的 .eslintrc 和 package.json 设置。我应该怎么做才能修复错误?包.json
{
"name": "raonair-frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"eslint-config-react-app": "^6.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"prepare": "husky install"
},
"parser": "babel-eslint",
"eslintConfig": {
"extends": [
"react-app",
"airbnb",
"plugin:flowtype/recommended"
],
"plugins": [
"flowtype"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@babel/eslint-parser": "^7.15.0",
"@babel/eslint-plugin": "^7.14.5",
"@babel/plugin-syntax-jsx": "^7.14.5",
"eslint": "^7.32.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-flowtype": "^5.9.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",
"husky": "^7.0.1",
"prettier": "^2.3.2"
}
}
.eslintrc
{
"env": {
"browser": true,
"node": true
},
"extends": [
"airbnb",
"airbnb/hooks",
"prettier"
],
"parser": "@babel/eslint-parser",
"parserOptions": {
"sourceType": "module",
"allowImportExportEveryWhere": false,
"ecmaFeatures": {
"globalReturn": false,
"jsx": true
},
"ecmaVersion": 2020,
"babelOptions": {
"configFile": "./babel.config.js"
}
},
"plugins": [
"jsx-a11y",
"react-hooks",
"@babel/",
"flowtype",
"import"
],
"rules": {
"import/no-anonymous-default-export": "off",
"import/no-extraneous-dependencies": "off",
"import/order": [
"error",
{
"groups": [
"builtin",
"external",
"internal",
"parent",
"sibling"
],
"newlines-between": "always",
"alphabetize": {
"order": "asc",
"caseInsensitive": false
}
}
],
"import/prefer-default-export": "off",
"indent": [
"error",
2,
{
"SwitchCase": 1
}
],
"jsx-a11y/anchor-is-valid": "off",
"no-console": "error",
"no-unused-vars": "error",
"react/jsx-props-no-spreading": "off",
"react/react-in-jsx-scope": "off"
},
"settings": {
"import/resolver": {
"typescript": {}
},
"insert_final_newline": true
}
}
解决方案
在开发依赖项中安装 @babel-preset-react。
在 .eslintrc 文件中添加这个
... "解析器": "@babel/eslint-parser", “解析器选项”:{ ... "babelOptions": { “预设”:[“@babel/preset-react”] }, } ...
推荐阅读
- git - git merge -no-ff 传输提交历史,但不传输内容
- docker - 这是谷歌云构建错误吗?还是我做错了 Docker?
- angular - 如何使用最新的角度和离子版本创建离子角度启动器应用程序?
- javascript - 使用另一个对象的键从对象数组创建新数组
- javascript - 使用 Http 状态代码验证正确的 URL
- google-cloud-platform - 以编程方式/使用 PHP API 的项目的 Active Cloud Firestore 数据库
- installshield - 如何签署可以在任何地方运行的 exe 或 msix 安装程序
- scala - Deciding number of parameter to pass to a method "dynamically"
- amazon-web-services - Commands in .ebextensions fails on ElasticBeanstalk
- javascript - Angular ngmodel ignores value attribute in a form input