'Why getting firebase is not defined error?
Here's the code for the firebase.js file where I'm getting this error in spite of strictly adhering to the official documentation of Firebase.
firebase.js
import { initializeApp } from 'firebase/app';
import { getFirestore ,getDocs} from 'https://www.gstatic.com/firebasejs/9.6.3/firebase-firestore.js'
import { collection} from 'https://www.gstatic.com/firebasejs/9.6.3/firebase-firestore.js'
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
// Configuration
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
Solution 1:[1]
You can follow the Firebase documentation on initializing Cloud Firestore:
import { initializeApp } from "firebase/app";
import { getFirestore, getDoc, collection } from "firebase/firestore";
// TODO: Replace the following with your app's Firebase project configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
// ...
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
// Initialize Cloud Firestore and get a reference to the service
const db = getFirestore(app);
You can refer to this documentation to get started in your Cloud Firestore application.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | RJC |
