functions-framework-nodejs icon indicating copy to clipboard operation
functions-framework-nodejs copied to clipboard

FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing.

Open stot3 opened this issue 7 years ago • 10 comments

Hey I'm just upgrading from the functions emulator, and trying to use the new functions framework, it appears to be working okay, but the console.logs, do not print to the console. I want to also do some testing with some admin SDK stuff but I get this error message.

FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing.

Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail
Serving function...
Function: convertTileToWebP
URL: http://localhost:8080/

stot3 avatar Jun 26 '19 18:06 stot3

Hi @stot3, if you're using Firebase SDKs, we recommend running firebase serve command to emulate your functions. The documentation can be found here: https://firebase.google.com/docs/functions/local-emulator. You're getting this error because the Firebase CLI sets both FIREBASE_CONFIG and GCLOUD_PROJECT env vars for your functions so that they have the needed information to work when deployed, whereas the functions framework emulator does not do this extra step.

thechenky avatar Jun 26 '19 18:06 thechenky

Thank you, it worked, I thought this was the replacement, but I am wrong! thank you

stot3 avatar Jun 26 '19 18:06 stot3

In case this helps anyone else in the future. The issue with the local emulator is with debugging.
I was able to get functions-framework working with a Firebase project by setting a GCLOUD_PROJECT environment variable. the framework will then auto-calculate the corresponding FIREBASE_CONFIG values based off the GCLOUD_PROJECT variable only.

dvdmmc avatar Nov 27 '19 16:11 dvdmmc

GCLOUD_PROJECT Hi, can you please show how to debug a cloud function using functions-framework?

MGCataldo avatar Dec 18 '19 11:12 MGCataldo

Another solution to this is to only require the functions when the app is in the Google Cloud environment. I use a function to initialize the Admin App, which I only call in Google Cloud.

function getAppInDeployedFunctions() {
  const functions = require('firebase-functions');
  return admin.initializeApp(functions.config().firebase);
}

Because the module is not loaded when running the local emulator, that warning does not appear.

Also if anyone is interested, we use this function locally:

function getAppEmulator() {
  const serviceAccount = require("../../serviceAccountKey.json");
  process.env.FIRESTORE_EMULATOR_HOST = "localhost:8080";
  process.env.FIREBASE_FIRESTORE_EMULATOR_ADDRESS = "localhost:8080";
  admin
    .initializeApp({
      credential: admin.credential.cert(serviceAccount),
    });
  return admin.app();
};

benwinding avatar Apr 21 '20 03:04 benwinding

Hi @stot3, if you're using Firebase SDKs, we recommend running firebase serve command to emulate your functions. The documentation can be found here: https://firebase.google.com/docs/functions/local-emulator. You're getting this error because the Firebase CLI sets both FIREBASE_CONFIG and GCLOUD_PROJECT env vars for your functions so that they have the needed information to work when deployed, whereas the functions framework emulator does not do this extra step.

Where should I run the command? :s

APmadruga avatar Nov 13 '20 13:11 APmadruga

Thank you, it worked, I thought this was the replacement, but I am wrong! thank you

Where did you run the command? :S

APmadruga avatar Nov 13 '20 13:11 APmadruga

In case this helps anyone else in the future. The issue with the local emulator is with debugging. I was able to get functions-framework working with a Firebase project by setting a GCLOUD_PROJECT environment variable. the framework will then auto-calculate the corresponding FIREBASE_CONFIG values based off the GCLOUD_PROJECT variable only.

what value you set in GCLOUD_PROJECT?

RezaRahmati avatar Dec 13 '20 21:12 RezaRahmati

In case this helps anyone else in the future. The issue with the local emulator is with debugging. I was able to get functions-framework working with a Firebase project by setting a GCLOUD_PROJECT environment variable. the framework will then auto-calculate the corresponding FIREBASE_CONFIG values based off the GCLOUD_PROJECT variable only.

what value you set in GCLOUD_PROJECT?

You set it to your Firebase project id.

dvdmmc avatar Dec 14 '20 17:12 dvdmmc

I receive the very same error and I'm running my function in the GCP

the errors shows in the log every time i deploy the function

Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail

and the code is simple as:

const crypto = require("crypto");
const admin = require('firebase-admin');
 
admin.initializeApp();

const functions = require('firebase-functions');
exports.krakow = functions.https.onCall((data, context) => {});

what can i do

bolds07 avatar Oct 16 '21 18:10 bolds07