0
votes

this is my firebase sdk version

[email protected]

this is init code of firebase i cant solve this please help me for this error




export default function  initFirebase() {
    if(!firebase.apps.length){
        firebase.initializeApp(clientCredentials)

        if(typeof window !=='undefined'){
            if('measurementId' in clientCredentials){
                firebase.analytics()
                firebase.performance()
            }
        }
        console.log('firebase was successfully init')
    }
}

How i import firebase

import firebase from 'firebase/app'

import 'firebase/firestore'
import 'firebase/storage'
import 'firebase/analytics'
import 'firebase/performance'
1
Please edit your question to show how you import Firebase so that this code can reach it, and probably also what version of the SDK you're importing. I also highly recommend checking firebase.google.com/docs/web/setup, as there have been some breaking changes recently. - Frank van Puffelen
Please also include the Firebase SDK version in your update. - Dharmaraj
how I find Firebase SDK - viranga LH

1 Answers

0
votes

You are using the new Modular SDK (V9.0.0+) which is designed to facilitate tree-shaking (removal of unused code) to make your web app as small and fast as possible. If you want to use your existing code (V8 name-spaced syntax) then you would have to change your imports to compat versions as shown below:

import firebase from 'firebase/compat/app'
import 'firebase/compat/firestore'
// import 'firebase/compat/[SERVICE_NAME]'

However, I'd recommend upgrading to the new SDK. The modular/functional syntax looks like this:

import { initializeApp } 'firebase/app'
import { getAuth } from 'firebase/auth'
import { getFirestore } from 'firebase/firestore'

const app = initializeApp({ ...firebaseConfig })

const auth = getAuth(app)
const firestore = getFirestore(app)
// other Firebase services

You don't have to check if a default Firebase app instance already exists in the modular syntax. However, if you need to list Firebase instances, you can do so using getApps():

import { getApps } from 'firebase/app'

console.log(getApps())