【问题标题】:Getting Error when adding an async function on NodeJS在 NodeJS 上添加异步函数时出错
【发布时间】:2019-10-15 17:56:15
【问题描述】:

我正在尝试在node.js v6.11 上添加async 方法,但我收到Unexpected identifier 错误。

let fs = require('fs');
let Config = require('../somefolders/config.js');

module.exports = class SomeClassName {
  constructor(id = null) {

  }

  //Some other methods

  static async test1234(param) {

  }

  //Some other Static methods
}

这是我们得到的错误:

Error

【问题讨论】:

标签: javascript node.js asynchronous async-await


【解决方案1】:

屏幕截图中的错误告诉我们您使用的是不支持 async/await 的旧版 Node.js。 Node.js 已经有 async/await 多年了,但如果我回到 v7,我可以准确地复制你截图中的错误。

如果您更新到最新版本的 Node.js(或者甚至是模糊的最新版本),那么该代码就可以了。

【讨论】:

    【解决方案2】:

    使用 Node 7.6 或更高版本。 ES2017 中添加了 async/await。

    【讨论】:

      猜你喜欢
      • 2021-07-14
      • 2021-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多