首页 > 解决方案 > 无法解决 reactjs 中谷歌身份验证中的 firebase/app 错误

问题描述

我正在尝试在我的项目中使用 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 函数。

有谁知道是什么问题?我哪里错了?

标签: reactjsfirebasegoogle-authentication

解决方案


您需要导入firebase模块。

以下代码应该可以工作:

import * as firebase from 'firebase/app';

与您当前导入它的方式相反

import firebase from 'firebase/app';


推荐阅读