简体   繁体   English

未捕获的类型错误:_firebase__WEBPACK_IMPORTED_MODULE_0__.app.auth 不是 function

[英]Uncaught TypeError: _firebase__WEBPACK_IMPORTED_MODULE_0__.app.auth is not a function

ok so ive been building a discord clone with react redux, right now im stuck on the sign in page.好的,所以我一直在用反应 redux 构建 discord 克隆,现在我卡在登录页面上。 it keeps giving me this error "Uncaught TypeError: firebase__WEBPACK_IMPORTED_MODULE_0 _.app.auth is not a function" heres my code in firebase.js它一直给我这个错误“Uncaught TypeError: firebase__WEBPACK_IMPORTED_MODULE_0 _.app.auth is not a function”这是我在 firebase.js 中的代码

import { initializeApp } from "firebase/app";
import { getDatabase } from 'firebase/database';
import { getAuth } from "firebase/auth"
import { GoogleAuthProvider } from "firebase/auth";


const firebaseConfig = {
  apiKey: "AIzaSyD0RxEfG1qZ4Qsoelw5E6J0rIaJSP4BbXQ",
  authDomain: "diacromb.firebaseapp.com",
  projectId: "diacromb",
  storageBucket: "diacromb.appspot.com",
  messagingSenderId: "237625612351",
  appId: "1:237625612351:web:2527b57f858d5a4688008a",
  measurementId: "G-3DEREK47Q2"
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);

const db = getDatabase(app);
const auth = getAuth();



const provider = new GoogleAuthProvider();

export {auth , app };
export {provider};
export default db;  

heres my code for Login.js这是我的 Login.js 代码

import { Button } from '@material-ui/core'
import {  auth, app } from './firebase'
import { provider } from './firebase'
import { signInWithPopup } from "firebase/auth"

import React from 'react'
import './Login.css'


function Login() {
   /* const signIn = () =>{
        const googleAuthProvider = new GoogleAuthProvider();
        app.auth().signInWithPopup(googleAuthProvider);    
       } */

        const signIn = ()=>{
            var google_provider = provider;
            
            app.auth().signInWithPopup(provider)
            .then((re)=>{
                console.log(re)
            })
            .catch((err)=>{
                console.log(err) 
            }) 
        }
    

    return (
        <div className='login'>
            <h2> I am the login page</h2>
            
          
            <Button onClick={signIn}>Sign In</Button>
        </div>
    );
    }



export default Login

I have no idea whats going on, ive read some other posts and people are saying to install older versions of firebase, I tried to do that and it still didnt work.我不知道发生了什么,我阅读了其他一些帖子,人们说要安装旧版本的 firebase,我试图这样做,但它仍然没有用。 Ive been stumped on this for nearly 2 days now我已经为此困扰了将近 2 天了

I assume you are using firebase 9. there you have to use js modules.我假设你使用的是 firebase 9. 你必须使用 js 模块。

https://firebase.google.com/docs/web/modular-upgrade https://firebase.google.com/docs/web/modular-upgrade

import { getAuth, signInWithPopup, GoogleAuthProvider } from "firebase/auth";

const auth = getAuth();
signInWithPopup(auth, provider)
  .then((result) => {
    // This gives you a Google Access Token. You can use it to access the Google API.
    const credential = GoogleAuthProvider.credentialFromResult(result);
    const token = credential.accessToken;
    // The signed-in user info.
    const user = result.user;
    // ...
  }).catch((error) => {
    // Handle Errors here.
    const errorCode = error.code;
    const errorMessage = error.message;
    // The email of the user's account used.
    const email = error.email;
    // The AuthCredential type that was used.
    const credential = GoogleAuthProvider.credentialFromError(error);
    // ...
  });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我一直遇到这个错误: Uncaught TypeError: firebase_compat_app__WEBPACK_IMPORTED_MODULE_0__.default.auth is not a function - I keep running into this error: Uncaught TypeError: firebase_compat_app__WEBPACK_IMPORTED_MODULE_0__.default.auth is not a function 类型错误:_firebase_firebase__WEBPACK_IMPORTED_MODULE_8__.default.auth 不是 function - TypeError: _firebase_firebase__WEBPACK_IMPORTED_MODULE_8__.default.auth is not a function 未捕获的类型错误:_firebase__WEBPACK_IMPORTED_MODULE_3__.default.collections 不是 function - Uncaught TypeError: _firebase__WEBPACK_IMPORTED_MODULE_3__.default.collections is not a function 类型错误:firebase_app__WEBPACK_IMPORTED_MODULE_0___default.a.analytics 不是 function - TypeError: firebase_app__WEBPACK_IMPORTED_MODULE_0___default.a.analytics is not a function 如何修复此错误 TypeError: _components_firebase_Firebase__WEBPACK_IMPORTED_MODULE_2__.default.auth is not a function - How do I fix this error TypeError: _components_firebase_Firebase__WEBPACK_IMPORTED_MODULE_2__.default.auth is not a function React/Firebase 错误“未捕获(承诺中)TypeError:(0,_firebase__WEBPACK_IMPORTED_MODULE_1__.default)不是函数” - React/Firebase error "Uncaught (in promise) TypeError: (0 , _firebase__WEBPACK_IMPORTED_MODULE_1__.default) is not a function" Next.js TypeError: (0, firebase_auth__WEBPACK_IMPORTED_MODULE_1__.onAuthStateChanged) 不是 function - Next.js TypeError: (0 , firebase_auth__WEBPACK_IMPORTED_MODULE_1__.onAuthStateChanged) is not a function "类型错误:_fire__WEBPACK_IMPORTED_MODULE_1__.default.auth 不是函数" - TypeError: _fire__WEBPACK_IMPORTED_MODULE_1__.default.auth is not a function 未捕获的类型错误:__WEBPACK_IMPORTED_MODULE_0_react___default.a.createContext 不是 function - Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_0_react___default.a.createContext is not a function 获取类型错误:firebase_app__WEBPACK_IMPORTED_MODULE_0__.initializeApp 不是使用 Vue3 的 function,Firebase 8.5 - Getting TypeError: firebase_app__WEBPACK_IMPORTED_MODULE_0__.initializeApp is not a function using Vue3, Firebase 8.5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM