[英]can't resolve firebase/app error in google authentication in reactjs
I'm trying to use the firebase google authentication in my project but I get this error while compiling:我正在尝试在我的项目中使用 firebase google 身份验证,但在编译时出现此错误:
./src/firebase/firebase.utils.js Module not found: Can't resolve 'firebase' in 'C:\\Users...
./src/firebase/firebase.utils.js 模块未找到:无法解析 'C:\\Users...
This is my firebase.utils.js:这是我的 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;
Then I imported signInWithGoogle function in my sign-in component.然后我在我的登录组件中导入了 signInWithGoogle 函数。
Does anyone know what's the problem?有谁知道是什么问题? Where's my wrong?
我的错在哪里?
You need to import the firebase
module.您需要导入
firebase
模块。
The following code should work:以下代码应该可以工作:
import * as firebase from 'firebase/app';
as opposed to how you are currently importing it与您当前的导入方式相反
import firebase from 'firebase/app';
This code worked for me这段代码对我有用
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.