ESLint "Module build failed" eslint-config-airbnb 错误

ESLint "Module build failed" error with eslint-config-airbnb

我正在尝试建立一个 React 项目,该项目使用 webpack 和 ESLint 以及 ESLint 的 airbnb 配置。当我尝试使用 webpack dev server 启动项目时,出现以下错误:

"Module build failed: Error: /react-template/node_modules/eslint-config-airbnb/rules/react-a11y.js: ESLint configuration is invalid: - Unexpected top-level property "ecmaFeatures"."

这是使用 eslint-config-airbnb v. 15.0.1。我检查了 react-a11y.js 文件并确认存在 "ecmaFeatures" 的顶级 属性。我知道从 ESLint 2.0.0 开始,ecmaFeatures 现在应该位于 parserOptions 属性 下,但我不确定这是否仅适用于 .eslintrc 文件。如果可能,我想使用 airbnb 配置,因此非常感谢您提供的帮助。这是我的 .eslintrc 文件以供参考。

.eslintrc

{
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 2016,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "env": {
    "es6": true,
    "browser": true,
    "node": true,
    "jest": true
  },
  "extends": ["airbnb"]
}

您JSON无效。它缺少第一个引号 "parser";

{
  "parser": "babel-eslint",
  "parserOptions": {
  "ecmaVersion": 2016,
  "sourceType": "module",
   "ecmaFeatures": {
  "jsx": true
 }
},
  "env": {
  "es6": true,
  "browser": true,
  "node": true,
  "jest": true
 },
 "extends": ["airbnb"]
}

全局eslint已经从3.19.0-1升级到4.0.0-1,出现这个问题

eslint v4 is not yet supported in eslint-config-airbnb and eslint-config-airbnb-base

https://github.com/eslint/eslint/issues/8726#issuecomment-308367541

我想出了解决办法。

您必须编辑位于 ./node_modules/.bin/eslint-config-airbnb/rules/react-a11y.jsreact.js

react-a11y.js中删除:

ecmaFeatures: {
  jsx: true
},

并将其替换为:

parserOptions: {
  ecmaFeatures: {
    jsx: true,
  },
},

react.js 中删除:

ecmaFeatures: {
  jsx: true
},

你应该可以开始了。

另外,我现在正在查看 airbnb 的 repo,看起来他们差不多一个月前修复了它,但我今天才重新安装了 eslint-config-airbnb,所以我不确定那里发生了什么。

这里是 react-a11y.js diff and the react.js diff 的链接。它们准确地显示了您需要 add/remove.