Skip to content
Advertisement

Parsing error: Unexpected token => when trying to deploy firebase cloud function. I couldn’t find any answers on here

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. enter image description here

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.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement