admin管理员组文章数量:1305277
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'
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'
Share
Improve this question
edited Sep 13, 2021 at 6:06
viranga LH
asked Sep 13, 2021 at 2:32
viranga LHviranga LH
382 silver badges10 bronze badges
3
- 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 remend checking firebase.google./docs/web/setup, as there have been some breaking changes recently. – Frank van Puffelen Commented Sep 13, 2021 at 3:40
- Please also include the Firebase SDK version in your update. – Dharmaraj Commented Sep 13, 2021 at 4:07
- how I find Firebase SDK – viranga LH Commented Sep 13, 2021 at 5:04
3 Answers
Reset to default 8You 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 pat
versions as shown below:
import firebase from 'firebase/pat/app'
import 'firebase/pat/firestore'
// import 'firebase/pat/[SERVICE_NAME]'
However, I would remend upgrading to the new SDK. The modular/functional syntax looks like this:
import { initializeApp } from '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())
Below is what worked for me, the issue started after I upgraded to Firebase 9
import firebase from 'firebase/pat/app';
import * as firebaseui from 'firebaseui'
import 'firebaseui/dist/firebaseui.css'
My firebase initialization looks like below:
let ui = firebaseui.auth.AuthUI.getInstance()
if (!ui) {
ui = new firebaseui.auth.AuthUI(firebase.auth())
}
ui.start('#firebaseui-auth-container', {
signInFlow: isDesktop() ? 'popup' : 'redirect',
callbacks: {
signInSuccessWithAuthResult() {
window.location.assign(`/home`)
// firebase.auth().signOut()
return false
},
},
...
You can't use the Firebase Auth UI library with the modular SDK yet. Check this for more details.
版权声明:本文标题:javascript - Server Error TypeError: Cannot read properties of undefined (reading 'apps') - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741796709a2397978.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论