I got this error in my firebase.js and I got Uncaught TypeError: firebase_app__WEBPACK_IMPORTED_MODULE_0__.firestore is not a function in my console I tried to import firebase in different ways, but neither way solve my problem.
import * as firebase from "firebase/app";
import "firebase/auth";
import "firebase/firestore";
// firebase init - add your own config here
const firebaseConfig = {
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
};
firebase.initializeApp(firebaseConfig);
const db = firebase.firestore();
const auth = firebase.auth();
CodePudding user response:
You are trying to get firestore
from firebase
. However in your code, firebase
is corresponding to firebase/app
.
Your initialization for const db
must come from firebase/firestore
.
Try this:
import { getFirestore } from "firebase/firestore"
const db = getFirestore();
Firebase doc: https://firebase.google.com/docs/firestore/quickstart#web-version-9_1
Moreover, you will probably get the same issue for firebase.auth()
:
import { getAuth, createUserWithEmailAndPassword } from "firebase/auth";
const auth = getAuth();
Firebase doc: https://firebase.google.com/docs/auth/web/start