TypeError: firebase.getFirestore is not a function

1,393 views
Skip to first unread message

Francis Isberto

unread,
May 12, 2023, 6:50:59 PM5/12/23
to Firebase Google Group
Hello, I am getting an error when trying to initialize Firebase, what am I doing wrong here?

import firebase from "firebase/compat/app";
import "firebase/compat/firestore";
import "firebase/compat/auth";
import { getFirestore } from "firebase/compat/firestore";

const clientCredentials = {
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,
};

const App = firebase.initializeApp(clientCredentials)

export const DB = getFirestore(App)
Heres the error message Unhandled Runtime Error

TypeError: (0 , firebase_compat_firestore__WEBPACK_IMPORTED_MODULE_1__.getFirestore) is not a function

Thanks in advance Francis.

Dale Nguyen

unread,
May 14, 2023, 11:05:37 AM5/14/23
to Firebase Google Group
Hi Francis,

You are using v9, so you should remove the `compat` in the imports. Same with the others.

import
{ getFirestore } from "firebase/firestore";

Thanks,

Reply all
Reply to author
Forward
0 new messages