-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Error: Can't determine Firebase Database URL." after v1 Migration from Beta #220
Comments
@laurenzlong Unfortunately I'm seeing this again with some of my functions, but not all. |
@ahaverty, with the above snippets. How would you implement the workaround? |
Remove the try {
admin.initializeApp();
} catch(error) {
//TODO: ignoring until firebase-functions fix released
} |
I've yet to hit issues with that, I'll update here if I do. |
@ahaverty, that didn't work either; Same erroneous behavior. |
@zgosalvez Damn. Thoughts on using a temporary custom firebase config? |
I want to hold off a more complicated workaround until we get feedback from @laurenzlong (or anyone from the Firebase team). This may be a simple fix on their end and I'm going to sleep soon. Thank goodness it's still the weekday in SFO. I'll hang ten for now. Feel free to do Plan C in the meantime. 🤓 |
Deploying tonight (It's Friday in Ireland), I think I'll go with Plan C for now 🤓 |
According to @inlined (https://twitter.com/inlined/status/982277528751489025) we need to import firebase-functions before calling initializeApp() |
Ok, that didn't work either. import { AppOptions, initializeApp } from 'firebase-admin';
let firebaseConfig = JSON.stringify({
databaseURL: `https://${process.env.GCLOUD_PROJECT}.firebaseio.com`,
storageBucket: `${process.env.GCLOUD_PROJECT}.appspot.com`,
projectId: process.env.GCLOUD_PROJECT,
});
initializeApp(firebaseConfig as AppOptions); but I got this on deploy attempt:
|
TL;DR: Though it's a bit hacky, can you try requiring (background) Until then, requiring |
@inlined I've tried |
I just got the following working in my index.ts, although it looks like firebase-functions is favouring some internal firebase config call and if else'ing to this: import { AppOptions, initializeApp } from 'firebase-admin';
initializeApp({
databaseURL: `https://${process.env.GCLOUD_PROJECT}.firebaseio.com`,
storageBucket: `${process.env.GCLOUD_PROJECT}.appspot.com`,
projectId: process.env.GCLOUD_PROJECT,
}); Would you recommend sticking with this or going with the require('firebase-functions')? 🤔 |
Module loading in TypeScript has a few really subtle nuances to it; I think you've triggered lazy loading with the
(a If the GCLOUD_PROJECT trick works for you, then that's fine as long as the code is not open source. There exist a small percentage of projects in the world where that code won't work. The databaseURL or storageBucket may not be the GCLOUD_PROJECT if the project is old enough. |
@inlined, I changed the // https://github.com/firebase/firebase-functions/issues/220#issuecomment-379312738
// tslint:disable-next-line:no-import-side-effect
import 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp();
exports['debug'] = require(`${__dirname}/debug.js`); It kind of makes sense now since I removed |
@inlined Why isn't this documented anywhere in the docs (at least doesn't seem like it)? |
This was supposed to go away sooner. We're looking into ways to remove the subtlety rather than hiding it in docs. If we can't do this soon, then a doc note is certainly appropriate. |
I'm in the same situation except I'm using javascript. My first three lines are:
And I'm also getting the "Can't determine Firebase Database URL" error when a firebase function is called. Specifically, when admin.database() is called. |
Can you |
Good news: things suddenly started working again. Bad news: I'm not sure why. Basically I just did a whole bunch of npm installs and updates for everything I could.
B) Here are the dependencies of the package.json file within the functions folder of my git repo: |
Odd. Can you try the following lines after including
(If you have other secrets in runtime config, you'll want to cut those out before sharing) |
So runtimeconfig.json doesn't exist, but the output of the other two logs look normal: GCLOUD_PROJECT is [project name] FIREBASE_CONFIG is {"projectId":"[project name]","databaseURL":"https://[project name].firebaseio.com","storageBucket":"[project name].appspot.com"} |
Oh. I read too fast and missed the part where everything started working again. I suspect that when you reran |
I had the same issue solved it like this import * as admin from 'firebase-admin'; |
@Shery11 That is only valid on versions < 1.0 |
I also got the I solved it by using @Shery11 's solution:
This is a fresh project scaffolded today with the CLI. Here are my dependencies:
Why is the CLI configuring |
You must not have the latest CLI. |
Thanks @laurenzlong that was it. It's weird that the dependencies' versions are tied to the CLI version. I just scaffolded a TypeScript project and I got The other thing that confused me is that I've been already using v1 of |
That's because the CLI hardcodes templates for "firebase init", for example https://github.com/firebase/firebase-tools/blob/master/templates/init/functions/typescript/package.lint.json. So what gets initialized depends on your CLI version. |
Thanks for the info. Not such a great idea to hardcode templates if you ask me, but it's good to know. |
Yeah I've been meaning to make it dynamically pull in the latest versions from npm... but it keeps falling behind on my to do list. Great chance to make a PR if anyone has some time on their hand! |
* Scheduler * unit tests * Adds integration tests for scheduled functions * removing uninented commit * fixing version number * adding labels and test for labels * trigger tests off of call to cloud scheduler:run * adding region/runtime opts tests * Predictions Functions (#220) * Firebase Predictions Integration with Functions - Initial check in * Add predictions getter * Make API match what was in the review, and add unit tests. * Fix imports. * Add error handling. * Handle process.env.GCLOUD_PROJECT correctly. * Fix region. * Upper case RiskToleranceName. * Add changelog message. * formatting * cleaning up * Revert "Predictions Functions (#220)" (#226) This reverts commit 838597aa6df973462a50484ec1f50d625da3f633. * pr fixes * adding clarifying comments * starting on pubsub impl * adds pusbub.schedule() * switching tests over from https to pubsub * Change timezone to a method instead of an optional argument * use real eventType * remove extra slash * changelog * switch signature to onRun(context) * switches changelog to present tense
Just want to add that adding The problem: 'use strict';
global['firebase_admin'] = require('firebase-admin');
firebase_admin.initializeApp(); The solution 'use strict';
global['firebase_functions'] = require('firebase-functions');
global['firebase_admin'] = require('firebase-admin');
firebase_admin.initializeApp(); |
admin.initializeApp(functions.config().firebase); |
Version info
firebase-functions: 1.0.0
firebase-tools: firebase/firebase-tools.git#ll-fixfbconfig2 (3.18.1) See firebase/firebase-tools/issues/722
firebase-admin: 5.11.0
Test case
See steps to reproduce. Related to /issues/216.
Steps to reproduce
firebase init functions
(Choose TypeScript and TSLint during setup)cd functions
"express": "^4.16.3",
inpackage.json
rm -rf node_modules
thennpm install
index.ts
withdebug.ts
withnpm run deploy
https://us-central1-project-id.cloudfunctions.net/debug
Were you able to successfully deploy your functions?
Yes.
Expected behavior
HTTP Response
Status Code: 200
Body: OK
Actual behavior
HTTP Response
Status Code: 500
Body: {"code":"database/invalid-argument","message":"Can't determine Firebase Database URL."}
Firebase Functions Logs
The text was updated successfully, but these errors were encountered: