在NodeJS上添加异步功能时出现错误

时间:2019-10-15 08:47:42

标签: javascript node.js asynchronous async-await

我正在尝试在async上添加node.js v6.11方法,但我却遇到了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

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:0)

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