Repository navigation
Closed as duplicate
Closed as duplicate
Copy link
Labels
bugSomething isn't workingSomething isn't workingbundlerSomething to do with the bundlerSomething to do with the bundlerdeploy-firebasesingle-file-executablebun build --compilebun build --compile
Description
What version of Bun is running?
1.2.13
What platform is your computer?
Darwin 24.4.0 arm64 arm
What steps can reproduce the bug?
(Here is a repo with the minimal reproduction of this bug)
- Create an application with bun and Firebase Firestore
- Do a query with Firestore
- Bundle the app
- Run the app with
bun poc/poc.js - Experience the hang for 43 secs.
Error:
29 | */
30 | function callErrorFromStatus(status, callerStack) {
31 | const message = `${status.code} ${constants_1.Status[status.code]}: ${status.details}`;
32 | const error = new Error(message);
33 | const stack = `${error.stack}\nfor call at\n${callerStack}`;
34 | return Object.assign(new Error(message), status, { stack });
^
error: undefined undefined: undefined
code: undefined,
details: undefined,
metadata: Metadata {
internalRepr: Map {},
options: [Object ...],
set: [Function: set],
add: [Function: add],
remove: [Function: remove],
get: [Function: get],
getMap: [Function: getMap],
clone: [Function: clone],
merge: [Function: merge],
setOptions: [Function: setOptions],
getOptions: [Function: getOptions],
toHttp2Headers: [Function: toHttp2Headers],
toJSON: [Function: toJSON],
},
at callErrorFromStatus (/Users/jaapweijlandprive/Documents/WeijlandIT/darts-expo/node_modules/google-gax/node_modules/@grpc/grpc-js/build/src/call.js:34:30)
Full poc:
import { getApps, initializeApp, cert } from 'firebase-admin/app';
import { getFirestore } from 'firebase-admin/firestore';
export const getFirebaseServiceAccount = () => {
const serviceAccount = process.env.FIREBASE_SERVICE_ACCOUNT;
if (!serviceAccount) {
throw new Error(
'FIREBASE_SERVICE_ACCOUNT is not set in environment variables.',
);
}
return JSON.parse(serviceAccount);
};
// Initialize Firebase Admin only if it hasn't been initialized
if (getApps().length === 0) {
const serviceAccount = getFirebaseServiceAccount();
initializeApp({
credential: cert(serviceAccount),
});
console.log('Firebase Admin initialized.');
}
const firestore = getFirestore();
const run = async () => {
const user = await firestore
.collection('environments/development/users')
.doc('lyZ9eFzyJwNqqBZ8C4nzW8ahpw03')
.get();
console.log('Done fetching.');
console.log(user.data());
};
run();Commands:
bun build ./src/poc.ts --target bun --outdir ./poc --sourcemapbun poc/poc.js
What is the expected behavior?
Firestore fetching a document.
What do you see instead?
A hang for about 40 seconds, after which an error:
29 | */
30 | function callErrorFromStatus(status, callerStack) {
31 | const message = `${status.code} ${constants_1.Status[status.code]}: ${status.details}`;
32 | const error = new Error(message);
33 | const stack = `${error.stack}\nfor call at\n${callerStack}`;
34 | return Object.assign(new Error(message), status, { stack });
^
error: undefined undefined: undefined
code: undefined,
details: undefined,
metadata: Metadata {
internalRepr: Map {},
options: [Object ...],
set: [Function: set],
add: [Function: add],
remove: [Function: remove],
get: [Function: get],
getMap: [Function: getMap],
clone: [Function: clone],
merge: [Function: merge],
setOptions: [Function: setOptions],
getOptions: [Function: getOptions],
toHttp2Headers: [Function: toHttp2Headers],
toJSON: [Function: toJSON],
},
at callErrorFromStatus (/Users/[...]/Documents/[...]/node_modules/google-gax/node_modules/@grpc/grpc-js/build/src/call.js:34:30)
Additional information
- There are 10 documents in the
environments/development/userscollection - Running
bun src/poc.tsdoes work as expected, so it looks like it has something to do with building. - Version
firebase-admin: 13.3.0
Reacted by 21f1000419, Brian M Hunt, Gustavo Akira, Sebastian Obentheuer, Mario Cecchi, Mateo Hrastnik, melon-dog, Joey Eamigh and Goga Koreli
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingbundlerSomething to do with the bundlerSomething to do with the bundlerdeploy-firebasesingle-file-executablebun build --compilebun build --compile
Activity
kan2k commentedon May 18, 2025
encountered the same issue in a docker environment for bun 1.2.9
this solved it but doesnt support streaming
const firestore = initializeFirestore(app, { preferRest: true });
plgrazon commentedon Jun 9, 2025
@kan2k @JaapWeijland having this issue as well, but I was able to solve it by declaring
firebase-adminas an external moduleI know this is not optimal since it beats the purpose of compiling the app.
Andrii-Antoniuk commentedon Jul 28, 2025
similar happens for @grpc/grpc-js (loaded by @zilliz/milvus2-sdk-node)
Obiwarn commentedon Aug 20, 2025
same here. any idea where this may come from?
fwf-ben commentedon Nov 13, 2025
Just ran into this - really hard to diagnose, only happens in my built code in my docker image, I was not running the built code locally.
fix was:
Gorthog commentedon Dec 10, 2025
now even the workaround of using it as external doesn't work :-(
Gorthog commentedon Dec 10, 2025
this is a regression from bun 1.3.4
with bun 1.3.3 it works
if I change to latest image, oven/bun:alpine - when i start bun_app i get:
error: Cannot find module 'firebase-admin/app' from '/$bunfs/root/bun_app'MichaelTendoSsemwanga commentedon Apr 3, 2026
+1
blikblum commentedon Apr 13, 2026
I created an other repository that works without the need to create an service account: https://github.com/blikblum/bun-firebase
It uses firebase web/modular SDK instead of firebase-admin but the bug is the same / related to GRPC
Running
npm run start:bun(execute src directly) works fineRunning
npm run run:bun:dist(execute built js file) shows the errorgogakoreli commentedon May 21, 2026
We may have found the underlying mechanism for this class of bug. See #31158.
TL;DR: Bun's JSC uses
SIGPWR(signal 30) for thread suspension on Linux (ceb3e74, shipped ~v1.2.3). When anydlopen'd library spawns threads that don't handle SIGPWR, JSC's suspension retry loop becomes infinite — flooding the process with ~8,500 signals/second and permanently starving the event loop.Why this might explain your issue:
firebase-admin→@grpc/grpc-js→ native addons that may spawn background threads. If any of those threads don't acknowledge SIGPWR, you'd see the exact symptom: network calls hang indefinitely after bundling (which changes JIT tier-up behavior, triggering the suspension path more aggressively).Quick test: if you can reproduce the hang, run
strace -f -e tgkill <your_binary>and look for infinitetgkill(..., SIGPWR)in the output. If you see thousands of SIGPWR signals, it's the same bug.Full investigation with reproduction and strace proof: #31158
bundler: declare require inside a CommonJS wrapper whose body contain…
bundler: declare require inside a CommonJS wrapper whose body contain…
robobun commentedon Aug 15, 2026
This is the same bug tracked in #9367: bundling a google-gax/@grpc/grpc-js based client (here firebase-admin's Firestore, there @google-cloud/pubsub and friends) with
bun buildmakes every RPC fail with the identicalError: undefined undefined: undefinedfrom grpc-js callErrorFromStatus while the unbundled code works. The root-cause analysis in #9367 (protobufjs' eval("require") probe failing inside Bun bundles, so proto-loader serializers return Uint8Array instead of Buffer) was worked out on the Firestore case itself, and the same workarounds (REST fallback or --external) apply to both; please follow #9367 for updates. (#9367 is in turn being consolidated into #14891, which is where this will be tracked.)Duplicate of #9367
Please add a 👍 or any extra details over there so it all stays in one place. If this is actually a different problem, say so here and we'll reopen.