简体   繁体   English

使用eslint-config-airbnb ESLint“模块构建失败”错误

[英]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.jsreact.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 diffreact.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 in eslint-config-airbnb and eslint-config-airbnb-base eslint eslint-config-airbnbeslint-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.

相关问题 Eslint - 找不到 eslint-config-airbnb - Eslint - eslint-config-airbnb not find 带有 eslint-config-airbnb 的扩展名为“.js”的文件中不允许使用 JSX - JSX not allowed in files with extension ' .js' with eslint-config-airbnb 使用 eslint-config-airbnb 后出现 Missing file extension "tsx" for "./reducer" 错误 - Missing file extension "tsx" for "./reducer" error after using eslint-config-airbnb 在react.js中使用eslint-config-airbnb时,“ fetch”是未定义的,“ localStorage”是未定义的 - “fetch” is undefined and “localStorage” is undefined , on using eslint-config-airbnb in react.js 如何在未反应的项目中使用`eslint-config-airbnb`? - How can I use `eslint-config-airbnb` in a non-react project? Airbnb Eslint 配置在 >12 个版本上太慢 - Airbnb Eslint config is too slow on >12 versions eslint 与 airbnb 反应 - eslint react with airbnb Eslint airbnb和更漂亮的配置删除文本中的点后的所有空格 - Eslint airbnb and prettier config removes all spaces after dots in text 更漂亮的 eslint:使用 'prettier' 或 'plugin:prettier/recommended' 和 React Typescript airbnb eslint 配置 - Prettier eslint: use 'prettier' or 'plugin:prettier/recommended' with React Typescript airbnb eslint config 错误:找不到模块“eslint-config-flowtype” - Error: Cannot find module 'eslint-config-flowtype'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM