jtsafarikJ
Denoβ€’10mo agoβ€’
7 replies
jtsafarik

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


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


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


when ran, the output is
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?
Was this page helpful?