gpt4 book ai didi

reactjs - React NextJS Firebase 报错刷新 Firebase App named '[DEFAULT]' already exists

转载 作者:行者123 更新时间:2023-12-05 08:27:12 25 4
gpt4 key购买 nike

我启动了一个项目,在多个组件中导入 firebase 时发生错误。

在这个 firebase 启动文件中:

import firebase from 'firebase'
const firebaseConfig = {
apiKey: "fdsfsdfdsf",
authDomain: "fdsfdsfsdfdsf",
databaseURL: "sdfdsfdsf",
projectId: "dsfdsfdsf",
storageBucket: "dsfdsfdsf",
messagingSenderId: "dsfdsfsdfdsf"
}

const FbApp = firebase.initializeApp(firebaseConfig)

export default FbApp.auth()

然后在组件中:

import firebase from '../lib/firebaseClient'

单个组件运行良好,但如果我添加一个新组件:

import firebase from '../lib/firebaseClient' 

申请失败:

FirebaseError: Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app).

最佳答案

我有同样的问题,然后我发现了这个:

if (!firebase.apps.length) {
firebase.initializeApp({});
}

https://github.com/zeit/next.js/issues/1999

关于reactjs - React NextJS Firebase 报错刷新 Firebase App named '[DEFAULT]' already exists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44034691/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com