【问题标题】:can't resolve firebase/app error in google authentication in reactjs无法解决 reactjs 中谷歌身份验证中的 firebase/app 错误
【发布时间】:2020-05-04 13:52:19
【问题描述】:

我正在尝试在我的项目中使用 firebase google 身份验证,但在编译时出现此错误:

./src/firebase/firebase.utils.js 未找到模块:无法解析“C:\Users...”中的“firebase”...

这是我的 firebase.utils.js:

import firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/auth';


const config = {
    apiKey: "AIzaSyCcqIv_fjH5LTw7A6Q9hjevJfGTmN3nIqk",
    authDomain: "crwn-db-4b7c9.firebaseapp.com",
    databaseURL: "https://crwn-db-4b7c9.firebaseio.com",
    projectId: "crwn-db-4b7c9",
    storageBucket: "crwn-db-4b7c9.appspot.com",
    messagingSenderId: "659711574442",
    appId: "1:659711574442:web:1e28381cc2890ad32aabd3",
    measurementId: "G-0B6V9D8PRK"
  };



firebase.initializeApp(config);

export const auth = firebase.auth();
export const firestore = firebase.firestore();

const provider = new firebase.auth.GoogleAuthProvider();
provider.setCustomParameters ({ prompt: 'select_account' });
export const signInWithGoogle = () => auth.signInWithPopup( provider );   

export default firebase;

然后我在我的登录组件中导入了 signInWithGoogle 函数。

有谁知道问题出在哪里?我哪里错了?

【问题讨论】:

    标签: reactjs firebase google-authentication


    【解决方案1】:

    您需要导入firebase 模块。

    以下代码应该可以工作:

    import * as firebase from 'firebase/app';

    与您当前的导入方式相反

    import firebase from 'firebase/app';

    【讨论】:

    • 感谢您的回答,但我之前尝试过,但没有成功。
    • 我根据视频一步一步编写了这段代码,除此之外一切都运行良好:-(
    • 你安装了firebase吗? npm i firebase,检查你的 package.json 中是否存在 firebase。
    • 是的,我已经安装过了
    【解决方案2】:

    这段代码对我有用

    import firebase from 'firebase/app';
    import 'firebase/firestore';
    import 'firebase/auth';
    
    const config = {
        apiKey: "AIzaSyCcqIv_fjH5LTw7A6Q9hjevJfGTmN3nIqk",
        authDomain: "crwn-db-4b7c9.firebaseapp.com",
        databaseURL: "https://crwn-db-4b7c9.firebaseio.com",
        projectId: "crwn-db-4b7c9",
        storageBucket: "crwn-db-4b7c9.appspot.com",
        messagingSenderId: "659711574442",
        appId: "1:659711574442:web:1e28381cc2890ad32aabd3",
        measurementId: "G-0B6V9D8PRK"
    };
    
    
    firebase.initializeApp(config);
    
    export const auth = firebase.auth();
    export const firebase_store = firebase.firestore();
    
    const provider = new firebase.auth.GoogleAuthProvider();
    provider.setCustomParameters({ prompt: 'select_account'});
    
    export const signInWithGoogle = () => auth.signInWithPopup(provider);
    
    export default firebase_store;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-01
      • 1970-01-01
      • 2016-09-15
      • 2016-10-30
      • 1970-01-01
      • 2021-07-13
      • 2018-02-13
      • 1970-01-01
      相关资源
      最近更新 更多