当我在 JS 文件上运行 ESLint 时,遇到报错,错误信息如下:
Parsing error: unexpected token =>
Warning: React version not specified in eslint-plugin-react settings. See https://github.com/yannickcr/eslint-plugin-react#configuration .
项目环境及配置信息:
- 操作系统:macOS Catalina 10.15.7
- 开发软件:VS Code
- ESLint 版本: ^7.15.0
- Node 版本: v12.18.2
- npm 版本: 6.14.5
"babel-eslint": "^10.1.0",
"babel-jest": "^22.4.1",
"babel-preset-env": "^1.6.1",
"concurrently": "^3.6.0",
"eslint": "^7.15.0",
"eslint-plugin-react": "^7.22.0",
"jest": "^22.4.2",
"webpack": "^3.10.0",
"webpack-dev-middleware": "^2.0.4",
"webpack-dev-server": "^2.11.1",
"webpack-hot-middleware": "^2.21.0"
解决方法:
本地安装 babel-eslint
,我这里使用的是 yarn。
yarn add --dev babel-eslint
在 .eslintrc.js 中添加"parser"
配置项:
"parser": "babel-eslint"
删除非 React 项目中的不必要配置项:
// "extends": [
// "eslint:recommended",
// "plugin:react/recommended"
// ],
问题解决!