We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Liamarjit Bhogal • 1 year ago

Hi, this was a well written article but caused a lot of issues. I believe due to the use of older Firebase version. I was following this article as well as the latest Firebase docs and it caused some confusion. db.collection() is no longer a function since v8 I think. Instead, you now need something like this to import firestore:

import {
getFirestore, doc, setDoc
} from "https://www.gstatic.com/firebasejs/10.10.0/firebase-firestore.js";

And to get my external db.js to pick up my variables, I needed to store them in var not const and also needed to pass them into the window scope:

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
var db = getFirestore(app)
window.db = db
window.doc = doc
window.setDoc = setDoc