oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.52k stars 2.71k forks source link

Firebase admin SDK not working (Probably HTTP2 issue) #9228

Open Moe03 opened 7 months ago

Moe03 commented 7 months ago

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:

bun install express firebase-admin

Then do any query or try to get any docuement it will not work and will give this error:

error: Did not receive document for "voiceglow/z5dc3sj5m/analytics/JSON_STRING".

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"

error: Did not receive document for "voiceglow/z5dc3sj5m/analytics/JSON_STRING".
      at /mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/@google-cloud/firestore/build/src/document-reader.js:68:80
      at getAll (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/@google-cloud/firestore/build/src/index.js:1015:24)
      at get (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/@google-cloud/firestore/build/src/reference.js:234:32)
      at /mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/vg/handlers/agents_analytics.ts:260:106
      at agents_analytics (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/vg/handlers/agents_analytics.ts:252:40)
      at handle (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/express/lib/router/layer.js:95:5)
      at next (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/express/lib/router/route.js:149:13)
      at dispatch (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/express/lib/router/route.js:119:3)
      at handle (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/express/lib/router/layer.js:95:5)
      at /mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/express/lib/router/index.js:284:15
      at param (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/express/lib/router/index.js:365:14)
      at param (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/express/lib/router/index.js:376:14)
      at process_params (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/express/lib/router/index.js:421:3)       
      at next (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/express/lib/router/index.js:280:10)
      at /mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/index.ts:99:5
      at handle (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/express/lib/router/layer.js:95:5)
      at trim_prefix (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/express/lib/router/index.js:328:13)
      at /mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/express/lib/router/index.js:286:9
      at process_params (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/express/lib/router/index.js:346:12)      
      at next (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/express/lib/router/index.js:280:10)
      at /mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/request-ip/lib/index.js:139:5
      at handle (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/express/lib/router/layer.js:95:5)
      at trim_prefix (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/express/lib/router/index.js:328:13)
      at /mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/express/lib/router/index.js:286:9
      at process_params (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/express/lib/router/index.js:346:12)      
      at next (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/express/lib/router/index.js:280:10)
      at cors (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/cors/lib/index.js:188:7)
      at /mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/cors/lib/index.js:224:17
      at originCallback (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/cors/lib/index.js:214:15)
      at /mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/cors/lib/index.js:219:13
      at optionsCallback (/mnt/c/Users/Mohamed/Desktop/github_repos/custom-vf-nextjs/vg-docker/node_modules/cors/lib/index.js:199:9)

EDIT: 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

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.

Electroid commented 7 months ago

Could you provide some code, so we can reproduce?

ranger1214v commented 5 months ago
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.

Moe03 commented 5 months ago

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
markdomkan commented 5 months ago

Still happening with bun 1.1.4 running on docker

harrisrobin commented 4 months ago

This seems to be resolved in 1.1.12

gavinharris-dev commented 3 months ago

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).