-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Bun and firestore (firebase-admin) #8549
Comments
Was about to post the same issue, but @acoyfellow did it 2 hours before. Amazing :D Ran into the same issue. The same script runs OK with After a while I get:
|
It looks like we now get the response data into the http2 stream, but there seems to be a bug into |
Any update on this? Still having problems in 1.0.29 |
Any update here? It makes it unusable for a lot of projects with this piece broken :-) |
FWIW we are just now successfully using bun to run firestore rules testing against the emulator with @firebase/rules-unit-testing. Very few issues (and we got to remove a bunch of workarounds that were needed for node/jest), relatively painless transition. |
I have a similar problem but I get an error message. Using the same code in node.js without bun works without a problem. The document exists. When I try to get the whole collection, it only returns part of it.
Error: |
Hey this is still persistent for me on bun v: 1.1.3 running on windows 10 To reproduce: $ bun add firebase-admin then create a demo firebase project, create a firesotre database then create a collection named "users", add any sample doc, and paste the service account config then run the script. const admin = require("firebase-admin");
export const GLOBAL_SERVICE_ACCOUNT = {
projectId: "____",
privateKey:
"____",
clientEmail: "___",
};
const app = admin.initializeApp({
credential: admin.credential.cert(GLOBAL_SERVICE_ACCOUNT), // replace with your service account
});
export const db = app.firestore();
async function testFirestore() {
console.log('connecting..')
const userRef = await db.collection(`users`).limit(1).get();
console.log(userRef.docs[0].data());
}
testFirestore() Result successful for ts-node: ts-node --transpileOnly bun-firebase.ts
connecting..
{
photoURL: 'https://lh3.googleu****',
uid: '********',
displayName: 'Tedr****',
joinedAt: 1707503064,
location: '(d****',
referredFrom: '',
widgets: [],
email: '*****',
freeLTsTS: *****,
loadTokens: *****
} Result always undefined in bun $ bun run bun-firebase.ts
connecting..
14 | export const db = app.firestore();
15 |
16 | async function testFirestore() {
17 | console.log('connecting..')
18 | const userRef = await db.collection(`users`).limit(1).get();
19 | console.log(userRef.docs[0].data());
^
TypeError: undefined is not an object (evaluating 'userRef.docs[0].data')
at C:\Users\Mohamed\Desktop\github_repos\custom-vf-nextjs\vg-docker\bun_index.ts:19:17 |
Unfortunately, this is the only thing that prevents me from migrating to bun in all my backend projects. 🥲 |
Just published firebase-admin-rest: Tiny Typesafe Firebase Admin REST API wrapper that works on Vercel Edge functions, Bun, Cloudflare workers, Deno or any JS runtime. Have already been dealing with the same problems for ages now (Bun, workers), it was crucial we use workers tho so I had to use the firebase rest api, and it wasn't fun, that package might help someone out tho :) // firebase-admin
const db = app.firestore();
const docs = await db.collection(`users`).limit(10).get()
// firebase-admin-rest
const db = await initFirebaseRest().firestore();
const docRef = await db.doc<User>(`users`).limit(10).page(2).get(); // pagination too! |
this is great, thanks for the effort @Moe03. Will definitely explore using this for some projects. |
Confirmed. Do something about it! I want |
Are there any updates on this? I've been using the "firebase-admin-rest" by Moe03, but would be awesome to be able to use the official firebase package for stability sake. |
+1 this isn't supposed to do all the functionalities of the official sdk of course and is just a temporary solution I had to create |
+1 need this too, not sure what we can do in our monorepo with one repo of firebase functions |
would be good to have firebase working with bun, atm we cant use bun because we don't have access to firebase auth and storage buckets :( |
+1 gonna drop back to node for the time being... |
bummer, was planning to migrate to bun |
This works fine for me. using bun 1.1.20 import { initializeApp, type App } from 'firebase-admin/app';
import { getFirestore, Timestamp } from 'firebase-admin/firestore';
class FirebaseService {
app: App;
db: FirebaseFirestore.Firestore;
constructor() {
this.app = initializeApp();
this.db = getFirestore(this.app);
}
async writeDocument(collectionName: string, documentName: string, data: any, ttl?: number) {
try {
if (ttl) {
const ttlDate = new Date();
ttlDate.setSeconds(ttlDate.getSeconds() + ttl);
data.expiry = Timestamp.fromDate(ttlDate);
}
await this.db.collection(collectionName).doc(documentName).set(data);
} catch (error) {
console.error('Error writing document: ', error);
}
}
async readDocument<T>(collectionName: string, documentName: string) {
try {
const docRef = this.db.collection(collectionName).doc(documentName);
const docSnap = await docRef.get();
if (docSnap.exists) {
return docSnap.data() as T;
} else {
return null;
}
} catch (error) {
console.error('Error reading document: ', error);
return null;
}
}
}
export default new FirebaseService(); |
Anyone else experiencing the random number of records are fetched in bun runtime issue? Other than that, bun (v.1.1.21)<-->firebase is working fine for us. We are using Auth and Firestore at the moment. |
The Firebase team decided not to investigate the issue so my sincere hope is that the Bun team will get to the bottom of the problem with gRPC. |
Noting the potential workaround, to prefer the REST API and avoid GAX, might help here. const db = initializeFirestore(firebaseApp, { preferRest: true }); |
@brianmhunt Yes, fair enough, thank you for mentioning. We have started to experiment with the workaround and so far it's working well. Did you already give it a try? |
Same issue - huge blocker, but... the workaround to use Rest API seems to be holding up still. |
@JZubero unfortunately we are continuing to experience problems. We consistently see this species.
Bun also performs considerably worse, with an action in Node.js taking 14s on average, the equivalent bun is 22s. We have also noticed that bun sometimes returns incorrect data from Firestore. So there are three outstanding problems:
|
@cirospaciari is very actively working on improving the node:http2 implementation in Bun (which firestore and firebase use) to both be faster, pass more of Node.js’ test suite, and also support http2 server (instead of just the client) Sorry this isn’t good yet, but we will make it good |
@brianmhunt Uh, that's not pretty. Thanks for keeping us posted about this. I will share our future findings regarding this here. @Jarred-Sumner Thank you for letting us know. Could you maybe provide a rough ETA when this might land? Not wanna be pushy here, just for our internal planning 🙏 |
The fix for this will be part of the Bun v1.1.31 release |
@Jarred-Sumner Thank you for the great work! |
Can confirm that Firebase Firestore now appears to have functional parity. Our motivation to use bun isn't performance, we're mostly interested in the builtin transpilation, error traces, trajectory of the project, etc. That said I'll note that bun is slower for the use case I was testing above (reading many Firestore docs). Some benchmarks running the same code: node: 421215ms The performance delta is consistently proportional to the number of Firestore docs, so at large enough scale the compilation overhead becomes insignificant. @Jarred-Sumner FYI ^^ If the reproduction or cause of this is not apparent let me know and I can share more details. For us, it's not a priority, but please tag if it's of interest. |
What version of Bun is running?
1.0.23
What platform is your computer?
Linux 5.15.0-91-generic x86_64 x86_64
What steps can reproduce the bug?
What is the expected behavior?
I expect to be able to use npm package
firebase-admin
, specifically firestoreWhat do you see instead?
No errors, just hangs.
Additional information
No response
The text was updated successfully, but these errors were encountered: