New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Firebase App named '[DEFAULT]' already exists (app/duplicate-app) #1999
Comments
You can check if (!firebase.apps.length) {
firebase.initializeApp({});
} |
The solution: `import firebase from 'firebase' try { const fb= firebase |
the issue is due to calling the initialize method of firebase more than multiple times . me had this same issue . and i could fix it by restricting the initialize method call more than once . make the firebase configurations in one class and make it as singleton class . |
I am new to firebase and a recent web developer. I had this issue. My issue was caused by linking my javascript file in both the head and in the body of my html file. I specifically had both firebase and js script tags in the html head and another js script tag at the end of the body tag. My fix was to delete all script tags from the head and put them at the bottom of the body. |
That's my solution: // Config file
import * as firebase from "firebase";
const config = {...};
export default !firebase.apps.length ? firebase.initializeApp(config) : firebase.app();
// Other file
import firebase from '../firebase';
...
console.log(firebase.name);
console.log(firebase.database()); |
Brilliant solution! @Purii |
@Purii You just saved my day |
If you use firestore, use : export default !firebase.apps.length
? firebase.initializeApp(config).firestore()
: firebase.app().firestore(); |
@jide thanks I had to also include import * as firebase from 'firebase'
import 'firebase/firestore';
const config = {
apiKey: "***",
authDomain: "***",
databaseURL: "***",
projectId: "***",
storageBucket: "***",
messagingSenderId: "***"
};
export default !firebase.apps.length
? firebase.initializeApp(config).firestore()
: firebase.app().firestore(); |
I started a project based on https://github.com/zeit/next.js/tree/v3-beta/examples/with-firebase
The error I have when importing firebase in more than one component.
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()`
Then in the components:
import firebase from '../lib/firebaseClient'
With a single component works well, but if I add a new component with
import firebase from '../lib/firebaseClient'
the application fail:Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app).
FirebaseError: Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app).
The text was updated successfully, but these errors were encountered: