question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deployment error Can't determine Firebase Database URL.

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:35 (10 by maintainers)

github_iconTop GitHub Comments

7reactions
hiranya911commented, Dec 12, 2018

I can confirm that simply requiring firebase-functions before initializeApp() fixes the issue.

LOADING TIME: {"projectId":"******","databaseURL":"https://******.firebaseio.com","storageBucket":"******.appspot.com","cloudResourceLocation":"us-central"}
DEFAULT APP OPTIONS: { projectId: '******',
  databaseURL: 'https://******.firebaseio.com',
  storageBucket: '******.appspot.com',
  cloudResourceLocation: 'us-central',
  credential: 
   ApplicationDefaultCredential {
     credential_: MetadataServiceCredential { httpClient: HttpClient {} } } }

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.

4reactions
stanbarcommented, Dec 18, 2018

@kevinajian Yes, it fixed the problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't determine Firebase Database URL - Stack Overflow
I deployed a React app, but I'm receiving the error message: @firebase/database: FIREBASE FATAL ERROR: Can't determine Firebase Database URL. ...
Read more >
Can't determine Firebase Database URL - Reddit
I deployed a React app, but I'm receiving the error message: "u/firebase/database: FIREBASE FATAL ERROR: Can't determine Firebase Database ...
Read more >
Cloud functions crash with `Error: Can't determine Firebase ...
I faced this issue and after deep research, the problem was from the "firebase-functions" import. This error will happen if you imported firebase-functions ......
Read more >
Learn about using and managing API keys for Firebase - Google
An API key is a unique string that's used to route requests to your Firebase project when interacting with Firebase and Google services....
Read more >
Firebase Fatal Error: Can't Determine Firebase Database Url
be able to view and manipulate data in your project's Database console. not particularly useful for adding a lot of data or allowing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found