【问题标题】:ESLint complaints with "Unexpected token" on class async methodESLint 对类异步方法的“意外令牌”投诉
【发布时间】:2020-12-04 00:01:02
【问题描述】:

鉴于这个类:

class Foo {
  async bar() {
    
  }
}

ESLint 说 bar 是一个意外的标记。我的.eslintrc 文件是这样的:

{
    "env": {
        "browser": true,
        "commonjs": true,
        "es6": true
    },
    "parserOptions": {
        "sourceType": "module"
    },

    "extends": [
        "eslint:recommended"
    ],
    "plugins": [
        "import"
    ],
    "settings": {
        "import/extensions": [
            ".js"
        ]
    }
}

我不知道如何解决这个问题。

【问题讨论】:

  • async 函数是 ES2017,ES6 不支持它们
  • @FZs 那里,修改了标签。问题没有改变。

标签: javascript eslint ecmascript-2017


【解决方案1】:

我必须将ecmaversion 添加到配置文件中。它适用于这些设置:

{
    "env": {
        "browser": true,
        "commonjs": true,
        "es6": true
    },
    "parserOptions": {
        "sourceType": "module",
        "ecmaVersion": "2018"
    },

    "extends": [
        "eslint:recommended"
    ],
    "plugins": [
        "import"
    ],
    "settings": {
        "import/extensions": [
            ".js"
        ]
    }
}

【讨论】:

    猜你喜欢
    • 2020-09-06
    • 1970-01-01
    • 2021-10-08
    • 2018-10-21
    • 2018-01-02
    • 2019-11-22
    • 2019-12-25
    • 2022-01-02
    • 2017-11-21
    相关资源
    最近更新 更多