jtsafarik
jtsafarik6mo ago

Firebase: broken pipe when using npm

Hi, I've been playing around with Deno and Firebase/Firestore, put together a short script:
import "https://deno.land/x/xhr@0.4.3/mod.ts";
import { deleteApp, initializeApp } from "npm:firebase/app";
import { collection, getDocs, getFirestore } from "npm:firebase/firestore";

const firebaseConfig = JSON.parse(Deno.env.get("FIREBASE_CONFIG"));
const firebaseApp = initializeApp(firebaseConfig);
const db = getFirestore(firebaseApp);

(await getDocs(collection(db, "sample-collection"))).docs.forEach((doc) => {
console.log(doc.data());
});

await deleteApp(firebaseApp);
import "https://deno.land/x/xhr@0.4.3/mod.ts";
import { deleteApp, initializeApp } from "npm:firebase/app";
import { collection, getDocs, getFirestore } from "npm:firebase/firestore";

const firebaseConfig = JSON.parse(Deno.env.get("FIREBASE_CONFIG"));
const firebaseApp = initializeApp(firebaseConfig);
const db = getFirestore(firebaseApp);

(await getDocs(collection(db, "sample-collection"))).docs.forEach((doc) => {
console.log(doc.data());
});

await deleteApp(firebaseApp);
which, if I run (locally or in docker container, deno version 2.2.5), I get the following:
export FIREBASE_CONFIG='<CONFIG>' && deno run --node-modules-dir --allow-scripts=npm:@firebase/util@1.11.0,npm:protobufjs@7.4.0 --allow-env --allow-net test.js
{ "sample-field": "sample-value" }
error: Uncaught (in promise) Error: stream closed because of a broken pipe
at async node:http2:824:44
export FIREBASE_CONFIG='<CONFIG>' && deno run --node-modules-dir --allow-scripts=npm:@firebase/util@1.11.0,npm:protobufjs@7.4.0 --allow-env --allow-net test.js
{ "sample-field": "sample-value" }
error: Uncaught (in promise) Error: stream closed because of a broken pipe
at async node:http2:824:44
now if I change the imports to esm.sh ones, the issue with broken pipe goes away:
import "https://deno.land/x/xhr@0.4.3/mod.ts";
import { deleteApp, initializeApp } from "https://esm.sh/firebase@11.5.0/app";
import { collection, getDocs, getFirestore } from "https://esm.sh/firebase@11.5.0/firestore";

const firebaseConfig = JSON.parse(Deno.env.get("FIREBASE_CONFIG"));
const firebaseApp = initializeApp(firebaseConfig);
const db = getFirestore(firebaseApp);

(await getDocs(collection(db, "sample-collection"))).docs.forEach((doc) => {
console.log(doc.data());
});

await deleteApp(firebaseApp);
import "https://deno.land/x/xhr@0.4.3/mod.ts";
import { deleteApp, initializeApp } from "https://esm.sh/firebase@11.5.0/app";
import { collection, getDocs, getFirestore } from "https://esm.sh/firebase@11.5.0/firestore";

const firebaseConfig = JSON.parse(Deno.env.get("FIREBASE_CONFIG"));
const firebaseApp = initializeApp(firebaseConfig);
const db = getFirestore(firebaseApp);

(await getDocs(collection(db, "sample-collection"))).docs.forEach((doc) => {
console.log(doc.data());
});

await deleteApp(firebaseApp);
when ran, the output is
export FIREBASE_CONFIG='<CONFIG>' && deno run --allow-env --allow-net test.js
{ "sample-field": "sample-value" }
export FIREBASE_CONFIG='<CONFIG>' && deno run --allow-env --allow-net test.js
{ "sample-field": "sample-value" }
(no broken pipe, the exit status is 0) --- Could someone help me understand the difference between these approaches? Afaik the imported packages versions are matching, is there some other difference?
6 Replies
marvinh.
marvinh.6mo ago
That sounds like an unexpected behaviour. Can you file an issue for that here https://github.com/denoland/deno/issues ? My guess is that we have. a bug in our node streams implementation. esm.sh transpile stuff and likely gives you the browser entry of the firebase package vs the node one. And their browser entry likely uses web streams instead of node streams
jtsafarik
jtsafarikOP6mo ago
I was thinking an issue might be a better thing to do, but wanted to confirm first that I'm not doing anything wrong, thanks for the suggestion, I'll file it shortly.
jtsafarik
jtsafarikOP6mo ago
For reference, the issue is filed under https://github.com/denoland/deno/issues/28610
GitHub
Firebase: broken pipe when using npm · Issue #28610 · denoland/deno
Version: Deno 2.2.5 I've been playing around with Deno and Firebase/Firestore, put together a short script: import "https://deno.land/x/xhr@0.4.3/mod.ts"; import { deleteApp, initiali...
jtsafarik
jtsafarikOP5w ago
Reviving an old thread to ask a question, my original understanding was that Deno 2.x is compatible with Node, but looking at https://node-test-viewer.deno.dev/results/latest#http2 it seems that most of the tests are not passing, with specifically https://github.com/nodejs/node/blob/main/test/parallel/test-http2-client-socket-destroy.js reproducing the issue I'm having when using Firebase. Is the test tracker a somewhat of a good view of how much compatibility with Node there is?
GitHub
node/test/parallel/test-http2-client-socket-destroy.js at main · n...
Node.js JavaScript runtime ✨🐢🚀✨. Contribute to nodejs/node development by creating an account on GitHub.
marvinh.
marvinh.5w ago
yes and no. Many tests are failing because of missing APIs that are not important like a specific method on assert.*. That said the http2 module in particular is a weak spot in Deno's node compatibility layer. It's not well implemented at the moment
jtsafarik
jtsafarikOP5w ago
I see, thanks for the info

Did you find this page helpful?