Typeerror: _Firebase_Webpack_Imported_Module_2_.
Default.Collection Is Not a Function

TypeError: _firebase__WEBPACK_IMPORTED_MODULE_2__.
default.collection is not a function

You are using the new modular SDK (v9) which no longer uses firebase.firestore() namespace. I'd recommend following the documentation to learn about new syntax:

import database from './firebase';
import { doc, onSnapshot, collection, query, where, onSnapshot } from "firebase/firestore";

useEffect(() => {
const q = query(collection(db, "buddies"))
const unsub = onSnapshot(q, (querySnapshot) => {
console.log("Data", querySnapshot.docs.map(d => doc.data()));
});
}, [])

firebase__webpack_imported_module_2__.auth.
createuserwithemailandpassword is not a function.?

The createUserWithEmailAndPassword() is a top level function in the new Firebase Modular SDK. Try importing the function as shown below:

import { createUserWithEmailAndPassword } from "firebase/auth"
import { auth } from "../firebase.js"; // update path

const register = (e) => {
e.preventDefault();

// auth instance as first param
createUserWithEmailAndPassword(auth, email, password).then((auth) => {
// it successfully created a new user with email and password
if (auth) {
navigate.push('/')
}
})
.catch(error => alert(error.message))
}

You must import auth instance that is getAuth() exported from Firebase file and not from "firebase/auth" SDK. The first param in createUserWithEmailAndPassword() should be this auth instance but you only have email and password params right now.



Related Topics



Leave a reply



Submit