简体   繁体   中英

Getting Error when adding an async function on NodeJS

I am trying to add async method on node.js v6.11 but i, getting Unexpected identifier error.

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
}

This is the error We are getting:

Error

The error in the screenshot tells us you're using an old version of Node.js that doesn't have async / await support. Node.js has had async / await for years, but if I go back to v7, I can replicate exactly the error in your screenshot.

If you update to an up-to-date version of Node.js (or even a vaguely-recent one), that code is just fine.

use Node version 7.6 or above. async/await added in ES2017.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM