Open jdgamble555 opened 6 months ago
I found a few problems with this issue:
@jdgamble555 Thank you for raising this issue. Could you elaborate on the use case where the preferRest
option (as noted in https://github.com/firebase/firebase-admin-node/issues/1879) does not solve your issue?
Yes, this will not solve the problem as "Edge" computing cannot load packages like "fs", "stream", "child_process", "crypto", "os", etc... This are usually items that are required with grpc, protobuf protocol etc... but NOT with REST API.
J
setting preferRest
still loads these items
Ok I think I see what you're saying. Could you mention which Firebase products specifically would be useful to you in a "lite" SDK? You mentioned Firestore for one. Also, would you prefer a "tree-shakeable" API (like https://github.com/firebase/firebase-js-sdk) or an object-oriented API (like https://github.com/firebase/firebase-admin-node)?
In any case, this is a pretty big undertaking so I have no promises as to if, or when, such a product will become available. But it's helpful to gather yours (and others') requirements for a time when we decide to scope such a project.
Also, could you describe how you would envision authentication to work? Authentication in the firebase-node-admin SDK in non-google edge computing environments would likely need an "exported service account key file" (https://firebase.google.com/docs/admin/setup) and these environments often do not have access to the file system. Would it work, for example, to be able to specify the JSON contents of the key file rather than a path to the key file? Then, at runtime, the code would need to first obtain the key file from some other place (e.g. d1/kv/r2 in cloudflare workers) and specify it to the initialization function for Firebase.
Here is how I setup my Firebase Admin app now. I use the environment variables.
Firestore already has a "lite" version that works with the REST API. It will work on non-node runtimes. However, it is only Firestore (not Firebase Auth etc) so you can't use an authentication token nor fetch data behind Firestore Rules.
Here is an example of a package that tries to mimic what Firebase Admin should already do.
https://github.com/Moe03/firebase-admin-rest
I have seen enough of these packages built over the years, that they never keep up-to-date. This is how it should work out-of-the-box IMO.
Imagine:
import { getAuth } from 'firebase-admin/auth/lite';
import { getFirestore } from 'firebase-admin/firestore/lite';
Similar to how the frontend works.
J
@jdgamble555 Thank you for the explanation and the example from @Moe03. I've logged b/343978422 internally to track this feature request and will keep you apprised of developments. But TBH it's unlikely that this feature request will see much progress without more requests from the community. For anyone who would like to see this feature, please reply with a brief explanation of your use case to help us prioritize this!
Wow this is still an ongoing issue? (i got the notification from the previous one with GRPC slow init)
iirc last time i used the admin sdk, preferRest was firebase/firestore only, so making one call to do an admin function meant the request took about 8 seconds in cloud functions/aws lambda.
If your doing firebase auth with a backend like php (no firebase sdk), then you could be using a node based admin app to handle this, and loading the admin sdk was just always slow.
8 seconds for a user is just ridiculous, and the early solutions such as 'function keep alive / warmers' are really not dev friendly...
'oh hey our sdk is massive and takes a while to load, so spend more money with us keeping your code cached and it'll be fast'.
Sorry if i come across annoyed by this, but I had many issues with firebase over the years from bad/missing/stale docs, to issues like this just taking forever to get fixed.
hoping new firebase admin lite works on edge when compiling regularly it works, but when compiling for edge I get this error: Module not found: Can't resolve './build/Debug/farmhash.node'
^guessing its a firebase dependency?
how to use it with Bun?
Note that this repository specifically targets node (the name is firebase-admin-node
). Providing a version that works portably across JavaScript runtimes (e.g. deno, bun, cloudflare workers) is a significant undertaking to create and maintain long-term and not something that is prioritized at the moment. That being said, please continue to voice your interest in such an SDK so that we can get a sense of the customer demand for this feature. Thanks everyone!
@dconeybe - To be fair, it was built for Node before other Runtimes were popular and probably named to differentiate between go, python etc.
It would be advantageous to build a "lite" version, just like firebase-js-sdk
has, as it could speed up NodeJS loading times as well. I don't think you would need to rebuild the whole package, just allow more tree-shaking and less dependency needs per package. If you imported from firebase-admin/lite
for example, it would not import all the bulk package dependencies etc.
J
@jdgamble555 Thank you for your input. I don't disagree that there is value in providing a version that is decoupled from node.js. It's just a matter of prioritization.
I'm desperate for a lightweight version of the Firebase Admin SDK. There have been numerous complaints about the painfully slow cold start caused by the Admin SDK dating back to 2020.
Another vote for this.. we would like to use Firestore in a Vercel edge function, and as previously stated, the Vercel edge runtime is missing many packages required by Firebase Admin.
Another vote for this. We would like to have some functions at edge that depend on Firebase admin SDK.
+1
Edge functions offer really compelling benefits for certain applications, and are becoming increasingly popular as a result. The lack of an official SDK for Firestore in these environments is a big problem.
Here to +1 this. Our team has lost so much time dealing with the REST interface 'manually' as it is not exactly developer friendly ;)
+1
+1
+1
Is your feature request related to a problem? Please describe. Currently Firebase cannot run on Deno, Cloudflare, Vercel Edge, or Bun (among others). Firebase will mainly be used in Node Serverless environments with Cold Starts, which are unacceptable for many app developers.
Describe the solution you'd like If you don't require Authentication, you can use the "Firestore Lite" package. However, we cannot use Authentication or the Server Functions in order to keep our session. This is a HUGE problem and limits where Firebase can be deployed.
Describe alternatives you've considered Using the REST API. However, it is EXTREMELY cumbersome in order to convert JSON data to the data types that REST API uses, as well as the problems handling tokens etc.
Additional context
It would be nice to be able to use the FirebaseServerApp as well, but this would not have ALL the features we may need in other JS environments.
J