firebase-functions: FIREBASE_CONFIG not set when Node.js 10 function deployed

[REQUIRED] Environment info

firebase-tools: 6.8.0

Platform: Windows 10

[REQUIRED] Test case

I had a set of functions built using Node.js version 6. They were successfully deployed and running.

I took the following actions to upgrade to use a newer version of Node: – Upgraded my Windows development system to Node.js version 10.15.3 – Upgraded to latest Firebase tools: npm install -g firebase-tools – Upgraded Firebase SDK: npm install firebase-functions@latest firebase-admin@latest --save – Edited the project’s package.json file to include "engines" : { "node" : "10" }

With those changes, the firebase deploy --only functions command completed without error. However, immediately after deployment, an error log appeared in the Firebase console for each function: Warning, FIREBASE_CONFIG environment variable is missing. Initializing firebase-admin will fail.

Changing package.json file to specify version 8 instead of 10 resolved the problem: "engines" : { "node" : "8" } . Functions initialize and execute as expected.

[REQUIRED] Steps to reproduce

Described in test case

[REQUIRED] Expected behavior

Firebase tools should set FIREBASE_CONFIG to the appropriate default for the project.

[REQUIRED] Actual behavior

FIREBASE_CONFIG is not set if Node version of 10 is specified in package.json file.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 19
  • Comments: 28 (10 by maintainers)

Most upvoted comments

The fix has been rolled out to production. FIREBASE_CONFIG and functions.config() should now work properly in Node 10 runtime. Please let me know if anyone is still seeing issues. Thanks!

Quick update: we have identified and implemented the fix for unpopulated FIREBASE_CONFIG and functions.config() values. This should roll out to production sometime next week.

@MaximBazarov @peterpeterparker your issues are likely different and relating to GCLOUD_PROJECT environment variable missing from the Node 10 runtime (although it should work fine with Node 8). Please open a new issue about this.

Thanks @rilian for that report as well - these issues are connected since both functions.config() and FIREBASE_CONFIG are populated by reading in the .runtimeconfig.json file, which the SDK can no longer find in the Node 10 runtime.

While I have a pending SDK fix for this, upon further investigating, I think this is a bug in the functions backend, and should be fixed there (see https://github.com/firebase/firebase-functions/pull/434#issuecomment-490168973). We are working with the relevant teams to resolve these issues. Thanks for everyone’s patience!

Just to confirm, I see same error on https callable functions after upgrading to node 10

Warning, FIREBASE_CONFIG environment variable is missing. Initializing firebase-admin will fail

Same here, with Node v8 all fine, when I upgrade to Node v10 I get the following error which I provide with the stack trace I found in the Firebase console in case that would help:

Error: process.env.GCLOUD_PROJECT is not set.
    at DocumentBuilder (/srv/functions/node_modules/firebase-functions/lib/providers/firestore.js:99:23)
    at cloudFunctionNewSignature (/srv/functions/node_modules/firebase-functions/lib/cloud-functions.js:102:13)
    at cloudFunction (/srv/functions/node_modules/firebase-functions/lib/cloud-functions.js:151:20)
    at Promise.resolve.then (/srv/node_modules/@google-cloud/functions-framework/build/src/invoker.js:330:28)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Update firebase-tools

@rilian they serve different purposes. functions.config() is used if you’re storing some custom key value pairs. To set the keys, you would do firebase functions:config:set some-service.key=value. To use that value in your functions code, retrieve it as you did with functions.config().some-service.key (see these docs for more info).

FIREBASE_CONFIG is something that you shouldn’t need to worry about - it is automatically populated with your project information and allows you to use the Firebase Admin SDK to talk to Firebase, RTDB, or Storage, for example:

const admin = require('firebase-admin');
// FIREBASE_CONFIG is used here so you can initialize without params here:
admin.initializeApp();

// in your function:
exports.addMessage = functions.https.onRequest((req, res) => {
  // ...
  // FIREBASE_CONFIG helps you be able to use admin like this, by automatically 
  // knowing which Database URL you want to talk to
  admin.database().ref('/messages').push({text: 'hi'});
}

These docs provide more info on what FIREBASE_CONFIG looks like.

Does that help?

For those as me who had this annoying problem here comes the solution…

For some stupid reason firebase forces you to have this environment variables set EVEN IF YOU DON’T USE THEM (what was my case). to fix it you have 2 options

1- open google cloud functions -> click the function name -> edit -> add runtime variable -> them you have to manually inform the values of these two variables… THIS MUST BE DONE FOR EACH OF YOUR FUNCTIONS

2- you can copy paste the following code as the FIRST LINE of each of your firebase functions

process.env.GCLOUD_PROJECT = "YOURPROJECT ID";
process.env.FIREBASE_CONFIG = '{"projectId":"PROJECTID","databaseURL":"DATABASEURL","storageBucket":"BUCKET"}';

ATTENTION!!!

the FIREBASE_CONFIG isn’t an object it is A STRING in json format so pay attention while setting it (these guys from firebase somethings do the dumbest things)

after that you stop getting this error

This is a separate issue: https://github.com/firebase/firebase-functions/issues/437. Please follow that bug.