firebase-functions: Deployment error Can't determine Firebase Database URL.
Version info
"firebase-admin": "~6.0.0",
"firebase-functions": "^2.0.5",
> firebase --version
4.2.0
Steps to reproduce
in my package.json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "./node_modules/.bin/eslint .",
"serve": "firebase serve --only functions",
"shell": "firebase experimental:functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"@google-cloud/storage": "^1.7.0",
"@google-cloud/vision": "^0.5.0",
"child-process-promise": "^2.2.0",
"firebase-admin": "~6.0.0",
"firebase-functions": "^2.0.5",
"mkdirp": "^0.5.1",
"mkdirp-promise": "^5.0.1"
},
"devDependencies": {
"eslint": "^5.4.0",
"eslint-plugin-promise": "^4.0.0"
},
"engines": {
"node": "8"
},
"private": true,
"main": "src/index.js"
}
in my index.js
'use strict';
const admin = require('firebase-admin');
admin.initializeApp();
/**
* Storage triggers
*/
const storageTriggers = require('./storageTriggers');
exports.blurOffensiveImages = storageTriggers.blurOffensiveImages;
/**
* Database triggers
*/
const databaseTriggers = require('./databaseTriggers');
exports.sendPhotoCommentNotification = databaseTriggers.sendPhotoCommentNotification;
in my databaseTriggers.js
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const db = admin.database();
...
in my storageTriggers.js which is basically https://github.com/firebase/functions-samples/tree/Node-8/moderate-images
'use strict';
const admin = require('firebase-admin');
const functions = require('firebase-functions');
const mkdirp = require('mkdirp-promise');
const vision = require('@google-cloud/vision')();
const spawn = require('child-process-promise').spawn;
const path = require('path');
const os = require('os');
const fs = require('fs');
...
Were you able to successfully deploy your functions?
Previously yes, but not sure what changed from the previous deploy.
Actual behavior
firebase deploy --only functions
=== Deploying to 'vape-tool'...
i deploying functions
i functions: ensuring necessary APIs are enabled...
✔ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (74.13 KB) for uploading
✔ functions: functions folder uploaded successfully
i functions: updating Node.js 8 function blurOffensiveImages(us-central1)...
i functions: updating Node.js 8 function sendPhotoCommentNotification(us-central1)...
⚠ functions[blurOffensiveImages(us-central1)]: Deployment error.
Function load error: Code in file src/index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: Error: Can't determine Firebase Database URL.
at FirebaseDatabaseError.FirebaseError [as constructor] (/srv/node_modules/firebase-admin/lib/utils/error.js:39:28)
at new FirebaseDatabaseError (/srv/node_modules/firebase-admin/lib/utils/error.js:190:23)
at DatabaseService.ensureUrl (/srv/node_modules/firebase-admin/lib/database/database.js:75:15)
at DatabaseService.getDatabase (/srv/node_modules/firebase-admin/lib/database/database.js:52:26)
at FirebaseApp.database (/srv/node_modules/firebase-admin/lib/firebase-app.js:231:24)
at FirebaseNamespace.fn (/srv/node_modules/firebase-admin/lib/firebase-namespace.js:280:45)
at Object.<anonymous> (/srv/src/databaseTriggers.js:20:18)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
⚠ functions[sendPhotoCommentNotification(us-central1)]: Deployment error.
Function load error: Code in file src/index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: Error: Can't determine Firebase Database URL.
at FirebaseDatabaseError.FirebaseError [as constructor] (/srv/node_modules/firebase-admin/lib/utils/error.js:39:28)
at new FirebaseDatabaseError (/srv/node_modules/firebase-admin/lib/utils/error.js:190:23)
at DatabaseService.ensureUrl (/srv/node_modules/firebase-admin/lib/database/database.js:75:15)
at DatabaseService.getDatabase (/srv/node_modules/firebase-admin/lib/database/database.js:52:26)
at FirebaseApp.database (/srv/node_modules/firebase-admin/lib/firebase-app.js:231:24)
at FirebaseNamespace.fn (/srv/node_modules/firebase-admin/lib/firebase-namespace.js:280:45)
at Object.<anonymous> (/srv/src/databaseTriggers.js:20:18)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
Functions deploy had errors. To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 35 (10 by maintainers)
I can confirm that simply requiring
firebase-functions
beforeinitializeApp()
fixes the issue.Looks like in the prod environment it is the
firebase-functions
package that sets the environment variable. So if you initialize Admin SDK before requiring that, your code is going to break.@kevinajian Yes, it fixed the problem.
I have fixed the issue by adding
at the top of
index.ts
If anyone stumbles across this and you get to the bottom, have tried everything and it’s still not working. It could be this.
My issue was that I had not created a Realtime Database. I was only using Firestore so didn’t bother creating a a realtime database. I could not get my functions to deploy with something as simple as this in my index.js
Once I created a Realtime Database https://console.firebase.google.com/u/0/[project-name]/database everything worked
Thanks! Will close this out. We will work on adding better documentation for this issue.
@stasbar @nikhilag If possible can you try the suggested fix of putting
const functions = require('firebase-functions');
before callingadmin.initializeApp();
?@stasbar I ran into this issue as well. I feel it would help to keep this issue open until it has been fixed in firebase library. Ideally we shouldn’t need to do anything apart from
admin.initializeApp()
Any update on this topic? I just decided to update my firebase functions project with some new features, and I can’t seem to serve it locally at all, getting same database exception
Thanks for the detailed diagnosis! I am quite puzzled by this. I know this is not a satisfying answer, but could you move
const db = admin.database()
into thesendPhotoCommentNotification
function? Then maybe you will be able to deploy. (The trigger parsing process during deployment only executes global scope code, so code that is inside the function will not cause any issues)