'Firebase Question - Uncaught TypeError: firebaseApp.firestore is not a function
import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
const firebaseConfig = {
projectId: "projectId"
};
const firebaseApp = firebase.initializeApp(firebaseConfig);
const db = firebaseApp.firestore();
const auth = firebase.auth();
export { db, auth };
Solution 1:[1]
To fix your error, you need to add import 'firebase/compat/firestore' under your import statements. Also, check the documentation to update imports to v9 compat.
import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/firestore';
const firebaseConfig = {
...
};
const firebaseApp = firebase.initializeApp(firebaseConfig);
const db = firebaseApp.firestore();
const auth = firebase.auth();
export { db, auth };
Solution 2:[2]
You first need to import Firestore SDK to use it. Try adding the following import below auth:
import "firebase/compat/firestore"
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 |
| Solution 2 | Dharmaraj |
