Open Moe03 opened 7 months ago
Could you provide some code, so we can reproduce?
bun install firebase-admin
import admin from 'firebase-admin';
if (admin.apps.length === 0) {
admin.initializeApp();
}
const doc = await admin.firestore().doc('/foo/foo').get();
console.log('doc', doc.data());
Error Message
error: Did not receive document for "foo/foo".
But if NodeJS is used, then it can work properly. However, using Bun will encounter this problem.
Could you provide some code, so we can reproduce?
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
Still happening with bun 1.1.4 running on docker
This seems to be resolved in 1.1.12
I had the issue on 1.0.?? (sorry cannot remember the exact version but it was 1.0 something). Run bun upgrade
and tried again and it seems to be working now (on 1.1.13 after upgrade).
What version of Bun is running?
1.0.30 (latest canary )
What platform is your computer?
Microsoft Windows NT 10.0.19044.0 x64
What steps can reproduce the bug?
Setup a simple express API with firebase:
Then do any query or try to get any docuement it will not work and will give this error:
With nodejs it is always working but on bun sometimes it loads and other times it doesn't (only when you do a query, when you get a document normally it never works).
What is the expected behavior?
It should always give the value consistently as happens with Nodejs env
What do you see instead?
Should behave similar to how it is nodejs, currently it gives an error mentioning "cant find the document"
EDIT: this is still persistent for me on bun v: 1.1.3 running on windows 10
To reproduce:
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.
Result successful for ts-node:
Result always undefined in bun
Additional information
Probably caused by http2 as I guess its not implemented yet/missing some stuff, this issue is related to: https://github.com/oven-sh/bun/issues/4746
If there is an ETA for supporting http2 and firebase-admin on canary would be greatly appreciated.