【问题标题】:Don't understand ESLint arrow error不懂 ESLint 箭头错误
【发布时间】:2018-04-30 23:06:55
【问题描述】:

我不明白我看到的错误,也不明白我应该在我的 ESLint 配置中更改什么来修复它,经过一段时间的挖掘。


我有一个使用 ECMA 版本 6 (ES6) 的 JS 代码的 sn-p,如下所示:

const launchApp = async () => {
  await sequelize.sync()
  app.listen(config.port)
  console.log(`Server started on port ${config.port}.`)    
}

在上面的=> 是一个 eslint 错误,上面写着:

[eslint] Parsing error: Unexpected token => (22, 28)

我不明白为什么这被认为是一个意外的标记。其他 ES6 样式工作正常。我在package.json 文件中设置配置,ESLint 相关部分如下所示:

  "eslintConfig": {
    "parserOptions": {
      "ecmaVersion": 6
    },
    "env": {
      "node": true,
      "es6": true
    },
    "rules": {
      "semi": ["error", "always"]
    }
  }

我做错了什么?我必须添加哪些进一步的配置?我看了arrow-parensarrow-body-style。据我所知,他们都告诉我es6 标志应该足以允许箭头函数样式。

【问题讨论】:

    标签: javascript ecmascript-6 eslint


    【解决方案1】:

    箭头函数是 es2015,但 async 箭头函数是 es2017。将您的"ecmaVersion" 设置为2017(或更高),它应该可以工作。 See this finished proposals chart for when each ES feature post 2015 was added.

    【讨论】:

      猜你喜欢
      • 2016-11-08
      • 2017-07-02
      • 2018-07-24
      • 1970-01-01
      • 2017-09-13
      • 1970-01-01
      • 2020-07-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多