FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing.
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/
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.
Thank you, it worked, I thought this was the replacement, but I am wrong! thank you
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.
GCLOUD_PROJECT Hi, can you please show how to debug a cloud function using functions-framework?
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();
};
Hi @stot3, if you're using Firebase SDKs, we recommend running
firebase servecommand 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 bothFIREBASE_CONFIGandGCLOUD_PROJECTenv 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
Thank you, it worked, I thought this was the replacement, but I am wrong! thank you
Where did you run the command? :S
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?
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.
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