简体   繁体   English

Next.js、Firebase、未处理的运行时错误 - TypeError:无法读取未定义的属性“initializeApp”

[英]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,为了解决这个问题,

  1. downgrade and adjust firebase version that the library requires降级并调整库所需的 Firebase 版本
  2. or switch the library with another one to display authentication button.或将库切换为另一个库以显示身份验证按钮。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Mongoose 和 Next.js:未处理的运行时错误 TypeError:无法读取未定义的属性(读取“令牌”) - Mongoose and Next.js: Unhandled Runtime Error TypeError: Cannot read properties of undefined (reading 'Token') React JS,Firebase,TypeError:无法读取未定义的属性“initializeApp” - React JS, Firebase, TypeError: Cannot read property 'initializeApp' of undefined 未处理的运行时错误类型错误:当我尝试使用 next.js 的图像组件时无法读取未定义的属性(读取“调用”) - Unhandled Runtime Error TypeError: Cannot read properties of undefined (reading 'call') when I try to use the Image component of next.js 未处理的运行时错误类型错误:无法读取未定义的属性“计时器” - Unhandled Runtime Error TypeError: Cannot read property 'timer' of undefined 未捕获的类型错误:无法读取未定义的属性“initializeApp” - Uncaught TypeError: Cannot read property 'initializeApp' of undefined Next.js &amp; Firebase -&gt; TypeError:无法读取未定义的属性(读取“应用程序”) - Next.js & Firebase -> TypeError: Cannot read properties of undefined (reading 'apps') 错误 - 无法读取未定义的属性“initializeApp” - Error - Cannot read property 'initializeApp' of undefined 在 Firebase 中,我收到 Uncaught TypeError: Cannot read property &#39;initializeApp&#39; of undefined,但不确定为什么未定义“firebase”? - In Firebase I am getting an Uncaught TypeError: Cannot read property 'initializeApp' of undefined, but not sure why 'firebase' is not defined? 尝试在 Next.JS 上导入 Bootstrap,但显示“类型错误:无法读取未定义的属性 &#39;jquery&#39;” - Trying to import Bootstrap on Next.JS but says “TypeError: Cannot read property 'jquery' of undefined” Next.js 类型错误:尝试控制台记录 api 结果时无法读取未定义的属性“” - Next.js TypeError: Cannot read property '' of undefined when trying to console log api results
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM