reactjsfirebaseapitypeerrorpinterest

Cannot solve "TypeError: firebase__WEBPACK_IMPORTED_MODULE_1__.default.createUserWithEmailAndPassword is not a function" error


I am attempting to create new users with my react app using firebase, Unfortunately I seem to receive the same error message over and over.

I have read the threads and appeared to follow the instructions but nothing appears to be working.

I authorized firebase to accept account creating with email and password and I used npm install --save firebase

My firebase.js file

import firebase from "firebase";
import "firebase/auth";


const firebaseConfig = {
  apiKey: "AIzaSyCHPSB1S58MWb5E5gVXccN1p8DXgFNNuVw",
  authDomain: "pinterest-clone-843c8.firebaseapp.com",
  projectId: "pinterest-clone-843c8",
  storageBucket: "pinterest-clone-843c8.appspot.com",
  messagingSenderId: "1013112040906",
  appId: "1:1013112040906:web:bd97504bf14e75434d3333",
  measurementId: "G-W8VETWB8RF"
};

firebase.initializeApp(firebaseConfig)
const auth = firebase.auth()
export {auth}

My header.js file

import {useState} from "react"
import auth from "firebase"
const Header = ({setimageArray}) =>{

auth.createUserWithEmailAndPassword("john@website.com",
"123abbbbc")
.then((userCredential) => {
 
var user = userCredential.user;
console.log(user)

})
.catch((error) => {
  var errorCode = error.code;
  var errorMessage = error.message;
 
  });

I can't seem to get rid of "TypeError: firebase__WEBPACK_IMPORTED_MODULE_1__.default.createUserWithEmailAndPassword is not a function"

Thanks for any help!


Solution

  • I think you are not importing it correctly from your firebase.js file. Try to change the import in your header.js to this:

    import { useState } from "react"
    import { auth } from "./firebase" // I asume they are on the same level. If not add more ../