2

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

3
  • Welcome to Stack Overflow! Please take the tour, have a look around, and read through the help center, in particular How do I ask a good question? Post code, markup, and error messages as text, not as a picture of text. Why: meta.stackoverflow.com/q/285551/157247 Commented Oct 15, 2019 at 8:49
  • I am using v6.11. Thanks alot @T.J.Crowder Commented Oct 15, 2019 at 8:58
  • 1
    Yup, that's seriously out-of-date. :-) Current is v12, current LTS is v10: nodejs.org/en/download Commented Oct 15, 2019 at 8:59

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.