Home > Software design >  Firebase Question - Uncaught TypeError: firebaseApp.firestore is not a function
Firebase Question - Uncaught TypeError: firebaseApp.firestore is not a function

Time:02-28

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

CodePudding user response:

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

CodePudding user response:

You first need to import Firestore SDK to use it. Try adding the following import below auth:

import "firebase/compat/firestore"
  • Related