Skip to content
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

Can't determine Firebase Database URL when upgrading to 1.0 #228

Closed
0x-r4bbit opened this issue Apr 23, 2018 · 6 comments
Closed

Can't determine Firebase Database URL when upgrading to 1.0 #228

0x-r4bbit opened this issue Apr 23, 2018 · 6 comments

Comments

@0x-r4bbit
Copy link

0x-r4bbit commented Apr 23, 2018

This seems to be related to #220. However, the issue has been closed, even though this is still reproducible.

Basically what happens is that firebase(tools) isn't able to determine the firebase database URL.

I'm aware that admin.initializeApp() doesn't take any config values anymore as per the migration guide

However, according to the API docs, AppOptions are still supported, they are just optional. Read here for verification.

Now, in my particular case, I do need to pass AppOptions because we have to setup AppOptions.credential using admin.cert(). On this note, I'd be happy if someone can tell me if this is still the way to go, even though initializeApp() is "supposed" to be called without options :)

const conf = JSON.parse(process.env.FIREBASE_CONFIG);

const serviceAccount = functions.config().fb_service_account;

if (serviceAccount) {
  conf.credential = admin.credential.cert(<any>{
    private_key: serviceAccount.private_key,
    client_email: serviceAccount.client_email
  });
}

admin.initializeApp(conf);

I'm not sure if my config above ^ is causing this, but deploying my firebase functions result in:

Error: Error occurred while parsing your function triggers.

Error: Can't determine Firebase Database URL.
    at FirebaseDatabaseError.FirebaseError [as constructor] (/Users/pascalprecht/projects/machinelabs/machinelabs/firebase/functions/dist/node_modules/firebase-admin/lib/utils/error.js:39:28)
    at new FirebaseDatabaseError (/Users/pascalprecht/projects/machinelabs/machinelabs/firebase/functions/dist/node_modules/firebase-admin/lib/utils/error.js:190:23)
    at DatabaseService.ensureUrl (/Users/pascalprecht/projects/machinelabs/machinelabs/firebase/functions/dist/node_modules/firebase-admin/lib/database/database.js:75:15)
    at DatabaseService.getDatabase (/Users/pascalprecht/projects/machinelabs/machinelabs/firebase/functions/dist/node_modules/firebase-admin/lib/database/database.js:52:26)
    at FirebaseApp.database (/Users/pascalprecht/projects/machinelabs/machinelabs/firebase/functions/dist/node_modules/firebase-admin/lib/firebase-app.js:235:24)
    at Object.<anonymous> (/Users/pascalprecht/projects/machinelabs/machinelabs/firebase/functions/dist/invocation-processor/database.js:11:24)
    at Module._compile (module.js:662:30)
    at Object.Module._extensions..js (module.js:673:10)
    at Module.load (module.js:575:32)
    at tryModuleLoad (module.js:515:12)

Having trouble? Try firebase deploy --help
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @machinelabs/firebase-functions@0.30.1 deploy: `npm run build && firebase deploy && npm run clean_dist`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @machinelabs/firebase-functions@0.30.1 deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/pascalprecht/.npm/_logs/2018-04-23T11_23_57_904Z-debug.log

Any updates on an actual fix for this? All related issues I've found mainly suggest workarounds, or have been close with works-on-my-machine™.

Version info

firebase-functions:

1.0.1

firebase-tools:

3.18.1

firebase-admin:

5.12.0

@laurenzlong
Copy link
Contributor

Hey @PascalPrecht Your usage is fine. What the migration guide is trying to say is that functions.config().firebase has been removed. Therefore, if you were previously writing admin.initializeApp(functions.config().firebase), that should be modified to admin.initializeApp()

Sounds like you're running into a CLI bug that was fixed recently. Can you update by running npm i -g firebase-tools?

@0x-r4bbit
Copy link
Author

Hey @laurenzlong,

thank you for the quick feedback. Good point, I thought 3.18.1 was the latest available version. I'll update the firebase-tools and keep you posted here!

0x-r4bbit added a commit to 0x-r4bbit/machinelabs that referenced this issue Apr 24, 2018
0x-r4bbit added a commit to 0x-r4bbit/machinelabs that referenced this issue Apr 24, 2018
@0x-r4bbit
Copy link
Author

Okay so I just tried it with firebase-tools@3.18.4 and I'm running into the exact same error.

Not sure if you're up for it, but I've created a reproducible here: 0x-r4bbit/machinelabs@4da5272

In /firebase/functions run

$ npx yarn install
$ npm run deploy

This assume you're logged in with firebase-tools in one for your firebase projects. Also, you need to setup a service account.

If you don't have the time to run it yourself, no problem at all. I just wanted to be sure the information is there just in case you're interested.

@laurenzlong
Copy link
Contributor

Do you also have a global firebase-tools installed? I see your "deploy" script in package.json is npm run build && firebase deploy && npm run clean_dist, I'm pretty sure this could use the global firebase-tools on your machine unless you were to explicitly indicate:

npm run build && ./node_modules/firebase-tools/bin/firebase deploy && npm run clean_dist

@0x-r4bbit
Copy link
Author

Hi @laurenzlong

as a matter of fact, I don't have firebase-tools installed globally and always rely on the locally installed ones. npm scripts will use the locally installed version automatically as well.

I'm sorry I can't give any more pointers. I talked to a friend who didn't have problems upgrading at all. I'll have another look..

@0x-r4bbit
Copy link
Author

@laurenzlong sorry that this took so long.

I found some time to dig deeper into this and I guess I have to facepalm myself.

The answer to this problem is in the stacktrace of the error:

Object.<anonymous> (/Users/pascalprecht/projects/machinelabs/machinelabs/firebase/functions/dist/invocation-processor/database.js:11:24

It turns out that we have another initializeApp() call in our firebase functions source I wasn't aware of, that still used config().firebase.

Closing this as resolved. And thank you for your support, I really appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants