问题描述
我基于 https:/开始了一个项目/github.com/zeit/next.js/tree/v3-beta/examples/with-firebase
在多个组件中导入Firebase时出现错误.
The error I have when importing firebase in more than one component.
在此Firebase起始文件中:
In this firebase start file:
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'
使用单个组件可以很好地工作,但是如果我添加一个具有以下内容的新组件:
With a single component works well, but if I add a new component with:
import firebase from '../lib/firebaseClient'
应用程序失败:
Firebase:名为"[DEFAULT]"的Firebase应用已存在(应用/重复应用).FirebaseError:Firebase:名为'[DEFAULT]'的Firebase应用已存在(app/duplicate-app).
Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app).FirebaseError: Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app).
推荐答案
我遇到了同样的问题,然后我发现了这个问题:
I had same issue, then I found out this:
if (!firebase.apps.length) {
firebase.initializeApp({});
}
https://github.com/zeit/next.js/issues/1999
这篇关于React NextJS Firebase错误刷新名为"[DEFAULT]"的Firebase应用已存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!