Closed
Description
Related issues
[REQUIRED] Version info
node: 12
firebase-functions: 3.13.0
firebase-tools: 8.19.0
firebase-admin: 9.4.2
[REQUIRED] Test case
[REQUIRED] Steps to reproduce
If we only set "GCLOUD_PROJECT" environment variable and then running admin.initializeApp();
you get below error
@firebase/database: FIREBASE FATAL ERROR: Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com
[REQUIRED] Expected behavior
Function setup with no error
[REQUIRED] Actual behavior
getting below error
@firebase/database: FIREBASE FATAL ERROR: Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com
Were you able to successfully deploy your functions?
no
Rootcause analysis
in
firebase-functions/src/setup.ts
Line 54 in c69c9bc
in
firebase-functions/src/setup.ts
Line 57 in c69c9bc
the current code is
process.env.FIREBASE_CONFIG = JSON.stringify({
databaseURL: `${process.env.DATABASE_URL}` ||
`https://${process.env.GCLOUD_PROJECT}.firebaseio.com`,
storageBucket: `${process.env.STORAGE_BUCKET_URL}` ||
`${process.env.GCLOUD_PROJECT}.appspot.com`,
projectId: process.env.GCLOUD_PROJECT,
});
so if value of process.env.DATABASE_URL
be undifined
it will be converted to a string of 'undefined'
which will result the databaseUrl or storgaeBucket become a string value of 'undefined'
Fix:
Below code fixes the issues, I didn't have access to create branch and submit PR
process.env.FIREBASE_CONFIG = JSON.stringify({
databaseURL: process.env.DATABASE_URL ||
`https://${process.env.GCLOUD_PROJECT}.firebaseio.com`,
storageBucket: process.env.STORAGE_BUCKET_URL ||
`${process.env.GCLOUD_PROJECT}.appspot.com`,
projectId: process.env.GCLOUD_PROJECT,
});