reactjs - 无法解决 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 函数。
有谁知道是什么问题?我哪里错了?
解决方案
您需要导入firebase
模块。
以下代码应该可以工作:
import * as firebase from 'firebase/app';
与您当前导入它的方式相反
import firebase from 'firebase/app';
推荐阅读
- javascript - 使用 ES6 映射从反应道具构造数组
- http - 从非 URL 的 REST API 显示 PNG
- amazon-web-services - DynamoDB 和 Lambda 连接
- python - Python 输入按钮提交问题
- android - Android - 屏幕右侧的ConstraintLayout文本剪切
- r - 通过索引选择性地组合 R Dataframe
- swift4.1.5 - 当我尝试在我的设备中运行我的项目时,命令阶段快速执行错误
- javascript - 错误:单击按钮后更新电梯和用户的值
- javascript - 为什么 TypeError:无法读取未定义的属性“0”?
- r-markdown - 是否可以提高从 RMarkdown 的 TikZ 插入 Word 文档的图像的分辨率?