【问题标题】:I keep getting this error Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app)我不断收到此错误 Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app)
【发布时间】:2021-03-28 06:36:47
【问题描述】:
import React, { Component } from 'react'
import './App.css';

import "bootstrap/dist/css/bootstrap.min.css";
import  firebase from 'firebase/app';
import 'firebase/database';
import ThreadDisplay from './ThreadDisplay/components/ThreadDisplay';

class google extends Component {
  constructor(props) {
    super(props);
    const config =
     {
      apiKey: "",
      authDomain: "",
      projectId: "",
      storageBucket: "",
      messagingSenderId: "",
      appId: "",
      measurementId: ""
    };
     this.app = firebase.initializeApp(config);
    
    this.database = this.app.database();
  }
  
  render() {
    return (
      <ThreadDisplay database={this.database} />
    );
  }
}
export default google;

我只初始化一次 Firebase 应用程序,然后我一次又一次地收到此错误。 Firebase:名为“[DEFAULT]”的 Firebase 应用程序已存在(应用程序/重复应用程序)。那我该如何解决这个问题

【问题讨论】:

    标签: javascript firebase react-native web react-dom


    【解决方案1】:

    如果这是您调用initializeApp 的唯一地方,则可能是该组件被创建了多次。

    如果您找不到保证只调用一次的位置,我通常会发现最简单的方法是显式检查我们之前是否已初始化 Firebase:

    if (firebase.apps.length === 0) {
        this.app = firebase.initializeApp(config);
        
        this.database = this.app.database();
    }
    

    【讨论】:

      猜你喜欢
      • 2021-07-29
      • 2022-12-22
      • 2022-11-07
      • 1970-01-01
      • 2021-07-13
      • 2021-09-09
      • 2021-06-12
      • 2021-09-13
      • 1970-01-01
      相关资源
      最近更新 更多