4

I have node.js v8.3.0, and have this in my package.json:

  "engines": {
    "node": ">=8.3.0"
  }

And my test code for await/async:

async function x() {
    return "test";
}

exports.asyncTest = functions.https.onRequest((request, response) => async function() {
    response.end(await x());
});

Expected output: test
Observed output:

Is there a syntax error in your code?
Detailed stack trace: /user_code/index.js:12
async function x() {
      ^^^^^^^^
SyntaxError: Unexpected token function
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at getUserFunction (/var/tmp/worker/worker.js:372:24)

1 Answer 1

10

The Cloud Functions for Firebase runtime is currently Node.js v6.x, so async/await is not supported. There is an expectation that Node v8.x will be supported sometime after it enters Long-Term Support (LTS).

In the meantime, you'll need to use a transpiler like Babel or TypeScript to take advantage of async/await.

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

4 Comments

FYI: Not sure who downvoted this, but it is the correct answer. I'm a Firebaser and work closely with the Cloud Functions team.
Thanks for the info, do you have an idea when will v7.6 be supported?
We don't announce specific timelines for future work, but will be sometime after October 31 (which is when Node.js v8 goes LTS).
No -- just that Node v8 will happen sometime after Cloud Functions reaches general availability. We recommend using e.g. TypeScript for async/await support in the meantime.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.