-
Notifications
You must be signed in to change notification settings - Fork 970
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
Namespaced firebase-admin
access not working in emulator, works in production
#5460
Comments
Hey @tannerstern. I recently had to fix a similar issue, and I wonder if you might be having similar issue:
The latest firebase admin sdk (v11) is now "modular" and require changes like above. I'm not sure why the code is only erroring in the Emulator case, but I'd suggest you try to change the import path anyway and see if it helps. |
Hi @taeold thanks for the response, apologies for not responding sooner. I will try switching things out and using the new recommended entry points. I fully expect that to solve the errors. The issue for us is the inconsistency between the emulator and production. In past development, we (regrettably) relied heavily on passing the For shared code between our client- and server-side, most of the time we passed We rely on the emulator to test changes before going live, hence the problem with the two environments handling things differently. Edit: I suppose it is also worth noting that the documentation that outlines the switch to "modular" exports uses language like "We recommend developers to use these new entry points", which I read to mean "we recommend but do not require" this usage. |
Thanks for sharing your issue with detail @tannerstern. My guess is that the difference in execution environment between the emulated and the prod environment may be due to some of the old hacks we have in the codebase that tries to monkey-patch the firebase admin sdk. It's an ancient code, one that was useful when Firebase Emulator was still a useful thing, and it's a code it's difficult to remove without some heroic effort. I'm not surprised and a bit sad to see that it could've caused an issue like you are seeing. While I can't promise we'll cleanup that tech debt soon, I'll keep this your issue in mind. Going to close this issue for now - let us know if we can help with anything else (I'll ping the SDK team and see if we can update the wording as you suggested). |
Thanks for the follow-up @taeold, that seems fair. A question though: you don't believe Firebase Emulator to be useful anymore? Is that because of bugs such as these, or are there replacements / alternative methods for such things? |
The fix is to use:
instead of: |
After making several changes to our codebase recently, we discovered that we are unable to access
firebase-admin
sub-classes in various namespaces with the emulator. This may be an issue withfirebase-admin
itself, but the errors we are getting (see below) only appear when emulating our functions, and not on live code.Others experiencing similar issues with
firebase-admin
posted about it on an issue (transferred to discussion) on that project's repo. See this comment by pascalbe-dev. Granted, most comments in that thread seem to be related toesm
imports, and here we're usingcommonjs
. I'm not sure what to make of it.Environment info
firebase-tools: 11.21.0
Platform: Ubuntu (GitHub Codespace)
Test case
functions/index.js
index.js
functions/package.json
Steps to reproduce
Provided you have correctly initialized Firebase on the client, you can simply run
firebase emulators:start --only functions
and run/index.js
to call the test function. (Truthfully, I opened a page in our app and simply ran those two lines in the Chrome console. I don't believe the way in which the http function is called is relevant to the issue.)Expected behavior
Firebase Emulator UI would have logged the current timestamp (timestamp object
{ seconds: number, nanoseconds: number }
).Actual behavior
We get an error that looks like:
We first noticed this with
admin.firestore.Timestamp
, but then also withadmin.database.ServerValue
. In both cases,admin.firestore
andadmin.database
are both empty objects, renderingTimestamp
andServerValue
undefined.If, however, you boot up a local node session, you can get the following:
The text was updated successfully, but these errors were encountered: