[英]React Native firebase is undefined
嗨,我在手機上嘗試在 expo go 上運行我的 react-native 應用程序時不斷收到此錯誤
TypeError: undefined is not an object (evaluating '_app.default.apps') 錯誤顯示它指向下面代碼中第 19 行的 firebase 變量,在 if 語句中它說的是 firebase:
import firebase from 'firebase/app';
require('firebase/auth');
import Constants from 'expo-constants';
// Initialize Firebase
const firebaseConfig = {
apiKey: Constants.manifest.extra.apiKey,
authDomain: Constants.manifest.extra.authDomain,
projectId: Constants.manifest.extra.projectId,
storageBucket: Constants.manifest.extra.storageBucket,
messagingSenderId: Constants.manifest.extra.messagingSenderId,
appId: Constants.manifest.extra.appId,
measurementId: Constants.manifest.extra.measurementId
};
let Firebase;
if (firebase.apps.length === 0) {
Firebase = firebase.initializeApp(firebaseConfig);
}
export default Firebase;
這反過來又導致我相信不變量違反。
請問有什么幫助嗎?
FirebaseSDK 在新版本 9 中更改了他們的 API,因此現在import firebase from “firebase/app”
將不起作用
您需要使用import { initializeApp } from 'firebase/app';
啟動您的應用程序或從 firebase/compat/app 導入以使用舊 API
請參閱https://firebase.google.com/docs/web/modular-upgrade了更多的變化, https://firebase.google.com/docs/web/setup新API
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.