This warning is puzzling me. I know it appears when you call initializeApp without arguments, and I understand that the warning is very appropriate under those circumstances.
A configuration based on the project id is valid for my project, and so to avoid the warning I then explicitely form this configuration before passing it on like so:
// GCP_PROJECT seems to be required for cloud-functions where GCLOUD_PROJECT is missing
const projectId = process.env.GCP_PROJECT || process.env.GCLOUD_PROJECT;
assert(projectId, "Missing GCP_PROJECT or GCLOUD_PROJECT env variable");
const firebaseConfig = {
authDomain: `${projectId}.firebaseapp.com`,
databaseURL: `https://${projectId}.firebaseio.com`,
projectId,
storageBucket: `${projectId}.appspot.com`,
};
Firebase continues to give me the same warning and I don't see a reason for that.
This code is both used in and outside of the context of cloud functions. If anyone from Google is listening, I think it would be useful to have a clear overview in de documentation what the differences are for various components in GCP regarding these environment variables:
GCP_PROJECT
, GCLOUD_PRJOJECT
and GOOGLE_CLOUD_PROJECT
. A while ago I read a mention that GCLOUD_PRJOJECT
was being deprecated, but it seems to be still in active use.
I'm using firebase-admin version 10 but the behavior was the same with 9 AFAIK.
CodePudding user response:
IIRC, that warning is logged because FIREBASE_CONFIG
environment variable is missing. FIREBASE_CONFIG
is a JSON formatted string containing a configuration object with projectId
, databaseUrl
and storageBucket
.
The configuration object would look like this:
{
"databaseURL": "https://an-example.firebaseio.com",
"projectId": "an-example",
"storageBucket": "an-example.appspot.com"
}
Because the above object could be inferred from substituting in the project ID, it is implemented as a fallback even though it is deprecated. In modern Google Cloud Function runtimes, GCLOUD_PROJECT
is not even present, so the warning is to help alert you to the problem before you deploy your code.