Question Detail

I am using Firebase Real-time Database to React Native, I have imported Firebase like

import firebase from 'firebase';

var configure Firebase= {

apiKey: "FULL_API_KEY_PUT_HERE",

authDomain: "FULL_AUTHDOMAIN_PUT_HERE",

databaseURL: "https://FULL_databaseURL_PUT_HERE.com",

storageBucket: "FULL_storageBucket_PUT_HEREappspot.com",

};

const fireabaseConfig=firebase.initializeApp(configure Firebase);

export default class HomeScreen extends Component {

//.............Remain Business Logic here...............

}

 

after this snippet when I run the code it works fine first time but after some time it gives me the error 

firebase app named '[default]' already exists (app/duplicate-app)


Thread Reply

Hemant Sharma

- 1 months ago

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

This error occurs when you trying to initialize firebase again and again. It should be initialized at once and use to avoid Firebase app named '[DEFAULT]' already exists  you have to change your initialization style.

import firebase from 'firebase';
try {
firebase.initializeApp({
apiKey: "FULL_API_KEY_PUT_HERE",
authDomain: "FULL_AUTHDOMAIN_PUT_HERE",
databaseURL: "https://FULL_databaseURL_PUT_HERE.com",
storageBucket: "FULL_storageBucket_PUT_HEREappspot.com",
})
} catch (err) {
// we skip the "already exists" message which is
// not an actual error when we're hot-reloading
if (!/already exists/.test(err.message)) {
console.error('Firebase initialization error raised', err.stack)
}}
const firebaseApp= firebase;