Skip to content
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

Open
acoyfellow opened this issue Jan 29, 2024 · 20 comments
Open

Bun and firestore (firebase-admin) #8549

acoyfellow opened this issue Jan 29, 2024 · 20 comments
Labels
bug Something isn't working

Comments

@acoyfellow
Copy link

acoyfellow commented Jan 29, 2024

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?

import admin from 'firebase-admin'; // 12.0.0

const {
  GCLOUD_SERVICE_ACCOUNT,
  DATABASE_URL,
  STORAGE_BUCKET
} = process.env;

admin.initializeApp({
  credential: admin.credential.cert(JSON.parse(GCLOUD_SERVICE_ACCOUNT)),
  databaseURL: DATABASE_URL,
  storageBucket: STORAGE_BUCKET,
});

const firestore = admin.firestore();

const docRef = firestore.collection('global').doc('data');

// I believe this is whats hanging when using Bun 1.0.23:
const dataDoc = await docRef.get();

const data = dataDoc.data(); // { data: { version: '0.0.0' } }

console.log({ data });

What is the expected behavior?

I expect to be able to use npm package firebase-admin, specifically firestore

What do you see instead?

No errors, just hangs.

Additional information

No response

@acoyfellow acoyfellow added the bug Something isn't working label Jan 29, 2024
@carletex
Copy link

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 node. I have a simple script (similar to @acoyfellow's script) that hangs when trying to access the database (connection seems ok)

After a while I get:

29 | const CALL_INVOCATION_TRANSFORMER_SYMBOL = Symbol();
30 | function isFunction(arg) {
31 |     return typeof arg === 'function';
32 | }
33 | function getErrorStackString(error) {
34 |     return error.stack.split('\n').slice(1).join('\n');
                ^
TypeError: undefined is not an object (evaluating 'error.stack.split')
      at getErrorStackString (/home/**REDACTED**/node_modules/@grpc/grpc-js/build/src/client.js:34:12)
      at onReceiveStatus (/home/**REDACTED**/node_modules/@grpc/grpc-js/build/src/client.js:191:41)
      at onReceiveStatus (/home/**REDACTED**/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:360:138)
      at onReceiveStatus (/home/**REDACTED**/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:323:178)
      at /home/**REDACTED**/node_modules/@grpc/grpc-js/build/src/resolving-call.js:99:75

@brianmhunt
Copy link

@acoyfellow acoyfellow changed the title Bun and firestore-admin Bun and firestore (firebase-admin) Jan 29, 2024
@cirospaciari
Copy link
Collaborator

It looks like we now get the response data into the http2 stream, but there seems to be a bug into PassThrough({ objectMode: true }) that prevent us to get the response.

@zachsents
Copy link

Any update on this? Still having problems in 1.0.29

@patrick-nurt
Copy link

Any update here? It makes it unusable for a lot of projects with this piece broken :-)

@brianmhunt
Copy link

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.

@christianbauer1
Copy link

christianbauer1 commented Mar 26, 2024

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.
Using bun 1.0.35 and firebase-admin 12.0.0

When I try to get the whole collection, it only returns part of it.

  const serviceAccount = require(`./serviceAccountKey_dev.json`);
  const app = admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
  });

  const db = admin.firestore();

  const cityRef = db.collection("cities").doc("SF");
  const doc = await cityRef.get();
  if (!doc.exists) {
    console.log("No such document!");
  } else {
    console.log("Document data:", doc.data());
  }

Error:
19 | const document_1 = require("./document");
20 | const util_1 = require("./util");
21 | const logger_1 = require("./logger");
22 | /**
23 | * A wrapper around BatchGetDocumentsRequest that retries request upon stream
24 | * failure and returns ordered results.
^
error: Did not receive document for "cities/SF".

@duongdam
Copy link

duongdam commented Apr 12, 2024

now, with the latest version of bun, I get a similar error.

Ảnh màn hình 2024-04-12 lúc 16 06 08

@acoyfellow
Copy link
Author

now, with the latest version of bun, I get a similar error.

Ảnh màn hình 2024-04-12 lúc 16 06 08

I can confirm I see the same "did not recieve document for ..." error.

Firestore is a hugely popular document database, I'm very surprised this is not a higher priority for the Bun team.

Very eager to swap all of my projects (dev & prod) from Node to Bun, as this seems to be the only blocker.

@Mouvedia
Copy link

related: #9228, #9393

@Moe03
Copy link

Moe03 commented Apr 15, 2024

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

@puerschel93
Copy link

Unfortunately, this is the only thing that prevents me from migrating to bun in all my backend projects. 🥲

@Moe03
Copy link

Moe03 commented Apr 19, 2024

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!

@acoyfellow
Copy link
Author

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.

@xsubject
Copy link

Confirmed. Do something about it! I want bun :(

@imMadsen
Copy link

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.

@Moe03
Copy link

Moe03 commented May 21, 2024

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

@KatFishSnake
Copy link

+1 need this too, not sure what we can do in our monorepo with one repo of firebase functions

@bamtheboozle
Copy link

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

@AwakenedMind
Copy link

+1 gonna drop back to node for the time being...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests