React-Native:Firebase 错误:未创建 Firebase 应用程序 [默认] - 调用 Firebase App.initializeApp() (app/no-app)

msa*_*wel 8 firebase reactjs react-native firebase-authentication

当我尝试将 firebase 与我的 React Native 应用程序连接时,出现此错误。

Firebase 错误:未创建 Firebase 应用程序 [默认] - 调用 Firebase App.initializeApp() (app/no-app)

我在这里添加了我的代码-

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

   // Your web app's Firebase configuration
const RNfirebaseConfig = {
  apiKey: "........",
  authDomain: "note-app-rn.firebaseapp.com",
  projectId: "note-app-rn",
  storageBucket: "note-app-rn.appspot.com",
  messagingSenderId: ".....",
  appId: "......"
};

const app = initializeApp(RNfirebaseConfig);
export const auth = getAuth(app);
export const db = getFirestore(app);
Run Code Online (Sandbox Code Playgroud)

Shi*_*vam 7

尝试这个,

import firebase from '@react-native-firebase/app';
import '@react-native-firebase/auth';
import '@react-native-firebase/firestore';

const RNfirebaseConfig = {
  apiKey: "........",
  authDomain: "note-app-rn.firebaseapp.com",
  projectId: "note-app-rn",
  storageBucket: "note-app-rn.appspot.com",
  messagingSenderId: ".....",
  appId: "......"
};

let app;
if (firebase.apps.length === 0) {
    app = firebase.initializeApp(RNfirebaseConfig )
} else {
    app = firebase.app()
}

const db = firebase.firestore();
const auth = firebase.auth();
Run Code Online (Sandbox Code Playgroud)