Robert Kwon
Robert Kwon

Reputation: 33

When I try to use async keyword with firebase function, I got an error

I declared function like below:

exports.updateFriends = functions.https.onCall(async (data, context) => {...

But I got an error like:

Parsing error: Unexpected token =>

Does anybody know about this?

Upvotes: 0

Views: 195

Answers (2)

Killerpixler
Killerpixler

Reputation: 4050

Update to this. You don't have to use TypeScript if you don't want to. You can just add "engines": {"node": "8"} to the package.json file in the firebase function directory and async/wait will work just fine.

Firebase cloud functions uses node6 by default but has node 8 available!

Upvotes: 0

Doug Stevenson
Doug Stevenson

Reputation: 317760

Google Cloud Functions currently runs on node 6, which doesn't support async/await syntax in ECMAScript 2017. You will have to either write your JavaScript to use promises directly, or you can write your code in TypeScript, which can transpile async/await down to ECMAScript 2015, which is supported by node 6. You can set up your project to use TypeScript using the Firebase CLI as described in the documentation.

Upvotes: 1

Related Questions