【问题标题】:Cannot solve "TypeError: firebase__WEBPACK_IMPORTED_MODULE_1__.default.createUserWithEmailAndPassword is not a function" error无法解决“TypeError: firebase__WEBPACK_IMPORTED_MODULE_1__.default.createUserWithEmailAndPassword is not a function”错误
【发布时间】:2021-10-10 22:01:17
【问题描述】:

我正在尝试使用 firebase 使用我的 react 应用创建新用户,但不幸的是,我似乎一遍又一遍地收到相同的错误消息。

我已阅读线程并似乎按照说明进行操作,但似乎没有任何效果。

我授权 firebase 接受使用电子邮件和密码创建帐户,并且我使用了 npm install --save firebase

我的 firebase.js 文件

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}

我的 header.js 文件

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;
 
  });

我似乎无法摆脱“TypeError:firebase__WEBPACK_IMPORTED_MODULE_1__.default.createUserWithEmailAndPassword 不是函数”

感谢您的帮助!

【问题讨论】:

    标签: reactjs firebase api typeerror pinterest


    【解决方案1】:

    我认为您没有从firebase.js 文件中正确导入它。尝试将 header.js 中的导入更改为:

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

    【讨论】:

    • 我相信我可以很好地导入它。如果我删除函数调用,我可以 console.log(auth) 没有错误。
    • 是的。因为在firebase 中有一个auth,但是您想从自己的文件中获取它,因为您使用export {auth} 将其导出到那里
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-22
    • 2018-09-01
    • 2018-11-14
    • 2021-07-02
    相关资源
    最近更新 更多