[英]ESLint “Module build failed” error with eslint-config-airbnb
I am trying to set up a React project that uses webpack and ESLint with the airbnb config for ESLint. 我正在尝试设置一个React项目,该项目使用webpack和ESLint以及用于ESLint的airbnb配置。 When I try starting up the project with webpack dev server, I get the following error: 当我尝试使用webpack dev服务器启动项目时,出现以下错误:
"Module build failed: Error: /react-template/node_modules/eslint-config-airbnb/rules/react-a11y.js: ESLint configuration is invalid: - Unexpected top-level property "ecmaFeatures"." “模块构建失败:错误:/react-template/node_modules/eslint-config-airbnb/rules/react-a11y.js:ESLint配置无效: - 意外的顶级属性”ecmaFeatures“。”
This is using eslint-config-airbnb v. 15.0.1. 这是使用eslint-config-airbnb v.15.0.1。 I checked the react-a11y.js file and confirmed there is a top-level property of "ecmaFeatures". 我检查了react-a11y.js文件并确认有一个“ecmaFeatures”的顶级属性。 I know as of ESLint 2.0.0 ecmaFeatures are now supposed to be under the parserOptions property, but I'm not sure if that only applies to the .eslintrc file. 我知道从ESLint 2.0.0开始,ecmaFeatures现在应该在parserOptions属性下,但我不确定它是否只适用于.eslintrc文件。 I'd like to use the airbnb config if possible, so I appreciate any assistance. 如果可能,我想使用airbnb配置,所以我感谢任何帮助。 Here is my .eslintrc file for reference. 这是我的.eslintrc文件供参考。
.eslintrc .eslintrc
{
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 2016,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"env": {
"es6": true,
"browser": true,
"node": true,
"jest": true
},
"extends": ["airbnb"]
}
I figured out a solution. 我想出了一个解决方案。
You have to edit react-a11y.js
and react.js
located in ./node_modules/.bin/eslint-config-airbnb/rules/
. 你必须编辑react-a11y.js
和react.js
位于./node_modules/.bin/eslint-config-airbnb/rules/
。
In react-a11y.js
remove: 在react-a11y.js
删除:
ecmaFeatures: {
jsx: true
},
and replace it with: 并替换为:
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
In react.js
just remove: 在react.js
删除:
ecmaFeatures: {
jsx: true
},
and you should be good to go. 你应该好好去。
Also, I'm looking at the airbnb's repo right now and it looks like they fixed it almost a month ago, but I just reinstalled eslint-config-airbnb today, so I'm not sure what happened there. 此外,我现在正在看airbnb的回购,看起来他们差不多一个月前修复了它,但我今天刚重新安装了eslint-config-airbnb,所以我不确定那里发生了什么。
Here are links to the react-a11y.js diff and the react.js diff . 这里是react-a11y.js diff和react.js diff的链接 。 They show exactly what you need to add/remove. 它们准确显示了您需要添加/删除的内容。
Global eslint has been upgraded from 3.19.0-1 to 4.0.0-1 when the problem appeared for me. 当问题出现时,全局eslint已从3.19.0-1升级到4.0.0-1。
eslint
v4 is not yet supported ineslint-config-airbnb
andeslint-config-airbnb-base
eslint
eslint-config-airbnb
和eslint-config-airbnb-base
尚不支持eslint
v4
https://github.com/eslint/eslint/issues/8726#issuecomment-308367541 https://github.com/eslint/eslint/issues/8726#issuecomment-308367541
You JSON isn't valid. 你JSON无效。 It's missing quotes around first "parser"; 在第一个“解析器”周围缺少引号;
{
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 2016,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"env": {
"es6": true,
"browser": true,
"node": true,
"jest": true
},
"extends": ["airbnb"]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.