[英]Next.js, Firebase, Unhandled Runtime Error - TypeError: Cannot read property 'initializeApp' of undefined
I have no idea why this error happens... but I suspect this file causes something??我不知道为什么会发生这个错误……但我怀疑这个文件会导致什么?? Especially,
firebaseAuth={getAuth(app)}
might be a problem.特别是,
firebaseAuth={getAuth(app)}
可能是一个问题。 Before that, const app = initializeApp(firebaseConfig);
在此之前,
const app = initializeApp(firebaseConfig);
is defined in "../firebase/firebase"
在
"../firebase/firebase"
定义
import React from "react";
import StyledFirebaseAuth from "react-firebaseui/StyledFirebaseAuth";
import { app } from "../firebase/firebase";
import { getAuth, createUserWithEmailAndPassword, EmailAuthProvider, GoogleAuthProvider, GithubAuthProvider } from "firebase/auth";
// Configure FirebaseUI.
const uiConfig = {
signInFlow: 'popup',
signInSuccessUrl: "/",
signInOptions: [
EmailAuthProvider.PROVIDER_ID,
GoogleAuthProvider.PROVIDER_ID,
GithubAuthProvider.PROVIDER_ID,
],
};
export default function SignInScreen() {
return (
<div>
<h1>PolygonHR Login</h1>
<p>Please sign-in:</p>
<StyledFirebaseAuth uiConfig={uiConfig} firebaseAuth={getAuth(app)} />
</div>
);
}
With new version of Firebase the syntax to import is changed.使用新版本的 Firebase,导入的语法发生了变化。 Try with this:
import { initializeApp } from 'firebase/app';
试试这个:
import { initializeApp } from 'firebase/app';
I suggest you to read this post to identify and fix other problem in your app.我建议您阅读这篇文章以识别并修复您的应用程序中的其他问题。 https://firebase.googleblog.com/2021/08/the-new-firebase-js-sdk-now-ga.html
https://firebase.googleblog.com/2021/08/the-new-firebase-js-sdk-now-ga.html
Finally, I found that this library called "react-firebaseui/StyledFirebaseAuth", which I use above, support firebase version 8.xx instead of v9 above, so this is why this error message in title has been shown.最后,我发现我上面使用的这个名为“react-firebaseui/StyledFirebaseAuth”的库支持 firebase 版本 8.xx 而不是上面的 v9,所以这就是标题中显示此错误消息的原因。
To fix this,为了解决这个问题,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.