0

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.

Thijs Koerselman
  • 21,680
  • 22
  • 74
  • 108

1 Answers1

1

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.

samthecodingman
  • 23,122
  • 4
  • 30
  • 54
  • Thanks, that explains it but then I'd say the warning is a bug. If you construct a configuration and pass that to `initializeApp` like I do, it should not check for a FIREBASE_CONFIG env variable, because I'm assuming this variable would always be overruled by the passed-in arguments. – Thijs Koerselman Nov 08 '21 at 07:43
  • For now I'll work around it by adding this to my env vars `FIREBASE_CONFIG=__mute_warning` – Thijs Koerselman Nov 08 '21 at 07:50