Skip to content

FR: Use fetch() in v9 instead of XMLHttpRequest #4912

Closed
@satyarohith

Description

@satyarohith

I'm trying to use firebase v9 beta SDK with Deno. But the new v9 version uses legacy XMLHttpRequest which isn't supported on Deno. I'm curious if it is possible to migrate to fetch() for the new v9 version.

I used the following code.

import { initializeApp } from "https://cdn.skypack.dev/firebase@v9.0.0-beta.2/app";
import {
  collection,
  getDocs,
  getFirestore,
  query,
  where,
} from "https://cdn.skypack.dev/firebase@v9.0.0-beta.2/firestore";

const firebaseConfig = {
  /* Your config. */
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
const q = query(collection(db, "cities"), where("capital", "==", true));
const querySnapshot = await getDocs(q);
querySnapshot.forEach((doc) => {
  console.log(doc.id, " => ", doc.data());
});

The error I get when I run the above code:

 error: Uncaught ReferenceError: XMLHttpRequest is not defined
  this.a = new XMLHttpRequest();
               ^
    at X.h.ba (https://cdn.skypack.dev/-/@firebase/webchannel-wrapper@v0.4.1-sqRlJscQiE5UdiDRxbsU/dist=es2020,mode=imports/optimized/@firebase/webchannel-wrapper.js:1621:16)
    at lc (https://cdn.skypack.dev/-/@firebase/webchannel-wrapper@v0.4.1-sqRlJscQiE5UdiDRxbsU/dist=es2020,mode=imports/optimized/@firebase/webchannel-wrapper.js:944:94)
    at jc (https://cdn.skypack.dev/-/@firebase/webchannel-wrapper@v0.4.1-sqRlJscQiE5UdiDRxbsU/dist=es2020,mode=imports/optimized/@firebase/webchannel-wrapper.js:930:3)
    at Dd.h.Ba (https://cdn.skypack.dev/-/@firebase/webchannel-wrapper@v0.4.1-sqRlJscQiE5UdiDRxbsU/dist=es2020,mode=imports/optimized/@firebase/webchannel-wrapper.js:1937:88)
    at Fb (https://cdn.skypack.dev/-/@firebase/webchannel-wrapper@v0.4.1-sqRlJscQiE5UdiDRxbsU/dist=es2020,mode=imports/optimized/@firebase/webchannel-wrapper.js:661:11)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions