Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would a Firebase background function on Node.js 8 complain about an event parameter?

After a recent update, firebase-tools wants me to set my package.json engines setting to either node 6 or 8. When you set it to 6 it deploys the functions on Node 6 and otherwise Node 8.

With firebase-functions 1.0 the background function signature changed from event to data, context. I have migrated all my background functions long ago.

I noticed that according to the @gloud/functions docs (which differs from firebase-functions) you explicitly set the Node deployment target, and the distinction in API between the Node 6 and 8 runtimes is this same event vs data/context signature.

So in @gloud/functions the API change got rolled out in a different way than with firebase-functions.

Wat seems weird is that if I now deploy my firebase-functions with engines set to node 8, I get errors like this:

Cloud function needs to be called with an event parameter.

When I set engines to node 6, it says it is deploying my code on Node.js 6, and everything works as before.

Now that seems to be the opposite of what I would expect!

So I am using the up-to-date background functions API but I can't seem to run them properly on Node.js 8. Something seems to be messed up somewhere. Any clue?

like image 552
Thijs Koerselman Avatar asked Aug 03 '18 15:08

Thijs Koerselman


People also ask

Does firebase support node JS?

Firebase provides the tools and infrastructure you need to develop your app, grow your user base, and earn money. The Firebase Admin Node. js SDK enables access to Firebase services from privileged environments (such as servers or cloud) in Node. js.

How long can a firebase function run?

Time Limits60 minutes for HTTP functions. 10 minutes for event-driven functions.

Are firebase Functions async?

Most of Firebase's APIs are asynchronous. This might be confusing at first: you're making a call, for example to fetch some data from Firestore, but you don't get a result back.


1 Answers

The problem is the version of firebase-functions needs to be 2.0.0+ for node 8 runtime.

This error message appears in 1.x.x firebase-functions for me, and is gone after I upgrade it.

Note that firebase-admin also needs to be 5.13.0+.

like image 154
William Chong Avatar answered Sep 29 '22 10:09

William Chong