exports.sendInvite = functions.firestore .document("invites/{phoneNumber}") .onCreate(async (doc) => { //error is here I assume const from = "+<mynumber>"; const to = doc.data().phoneNumber; const text = "You can join the club now"; return client.messages.create(from, to, text); });
my .eslintrc.js
module.exports = { root: true, env: { es6: true, node: true, }, extends: [ "eslint:recommended", "google", ], rules: { quotes: ["error", "double"], }, };
My firebase cloud function is throwing this error Parsing error: Unexpected token =>
.
Does anyone know why this is happening? I am using javascript btw not TS.
Advertisement
Answer
Arrow functions are an ES6 feature, but here you have an async arrow function.
Async functions in general are an ES8 (or 2017) feature. Therefore you need to specify the following setting at the root of your config:
parserOptions: { ecmaVersion: 8 // or 2017 }
This will let the parser know to expect the =>
token after async
is used.