[英]React Native firebase is undefined
Hi I keep getting this error when trying to run my react-native app on expo go on my phone嗨,我在手机上尝试在 expo go 上运行我的 react-native 应用程序时不断收到此错误
TypeError: undefined is not an object (evaluating '_app.default.apps') and the error shows it pointing to the firebase variable on line 19 in the code below in the if statement where it says firebase: 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;
this in turn is causing I believe an Invariant violation as well.这反过来又导致我相信不变量违反。
Any help please?请问有什么帮助吗?
FirebaseSDK changed their API in the new version 9 so now import firebase from “firebase/app”
won't work FirebaseSDK 在新版本 9 中更改了他们的 API,因此现在import firebase from “firebase/app”
将不起作用
You need to use the import { initializeApp } from 'firebase/app';
您需要使用import { initializeApp } from 'firebase/app';
to initiate your app or import from firebase/compat/app to use the old API启动您的应用程序或从 firebase/compat/app 导入以使用旧 API
Refer to https://firebase.google.com/docs/web/modular-upgrade for more about the changes and https://firebase.google.com/docs/web/setup for the new 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.