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
New Line in JavaScript Alert Box
Node.Js Tail-Call Optimization: Possible or Not
How to Redefine a JavaScript Class's Method
Automatic Semicolon Insertion & Return Statements
Get Event Listeners Attached to Node Using Addeventlistener
Positive Look Behind in JavaScript Regular Expression
How to Stop a Window.Setinterval in JavaScript
JavaScript .Replace Command Replace Page Text
Finding Longest String in Array
(Deep) Copying an Array Using Jquery
Executing JavaScript from Python
React - Preventing Form Submission
Js Function to Calculate Complementary Colour
Es6 Promise.All() Error Handle - Is .Settle() Needed
JavaScript .Queryselector Find <Div> by Innertext
How to Overcome the Cors Issue in Reactjs