Struggling to incorporate Firebase into a TypeScript/NextJS project, I have encountered difficulties. Despite successfully importing and initializing the app:
import * as firebase from "firebase/app";
import { collection, getDocs } from "firebase/firestore";
const firebaseConfig = ({
apiKey: "",
authDomain: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
});
firebase.initializeApp(firebaseConfig);
Upon page reload, an error arises:
FirebaseError: Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app).
To address this issue, I substituted:
firebase.initializeApp(firebaseConfig);
with
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
} else {
firebase.app();
}
This alteration results in a
TypeError: Cannot read property 'length' of undefined
. The Intellisense for apps
indicates Property 'apps' does not exist on type
, leaving me uncertain about the next step. Any assistance would be greatly appreciated.