0

I have deployed the following firebase function:

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';

admin.initializeApp();

// other functions

exports.createProfileDocument = functions.auth.user().onCreate(async user => {
    await admin.firestore().collection('profiles').doc(user.uid).set({
        userName: user.displayName
    })
});

This was working but recently stopped, when a new user account was created the function would simply not fire (nothing in the logs, no errors, no activity, etc.). I updated my dependencies to the following:

  "dependencies": {
    "firebase-admin": "^8.0.0",
    "firebase-functions": "^2.3.1",
    "firebase-tools": "^6.11.0"
  },

The function is now firing when I would expect but fails with the following error:

/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/index.js:740
    async initializeIfNeeded() {
          ^^^^^^^^^^^^^^^^^^

SyntaxError: Unexpected identifier
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.require (module.js:504:17)
    at require (internal/module.js:20:19)
    at FirebaseNamespace.get [as firestore] (/user_code/node_modules/firebase-admin/lib/firebase-namespace.js:329:29)

Any ideas?

CampbellMG
  • 2,090
  • 1
  • 18
  • 27

2 Answers2

0

It looks as though this was failing due to the async keyword before initializeIfNeeded() as this is not available in node 6. I was able to resolve the issue by adding

"engines": { "node": "8" }

To my package.json

CampbellMG
  • 2,090
  • 1
  • 18
  • 27
0

You need to update your node to version 8.x, which allows async hooks.

Upgrade: How to update nodejs from 6.x to 8.x?