Error: No Firebase App '[Default]' Has Been Created - Call Firebase App.Initializeapp()

Firebase error: No firebase app default has been created

I would recommend creating a separate file firebase.js and export Firebase services from there after initialization.

firebase.js

import firebase from 'firebase/app';
import 'firebase/firestore'

const firebaseConfig = {...};

if (!firebase.apps.length) {
firebase.initializeApp(config);
}

export const auth = firebase.auth();
export const firestore = firebase.firestore()

Then import these wherever you need them:

// App.js for example

import {firestore, auth} from './firebase.js'

//var docRef = firestore.collection("Products").doc("Items");

React-Native: Firebase Error: No Firebase App [DEFAULT] has been created - call Firebase App.initializeApp() (app/no-app)

try this,

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();

Error: [core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()

With the recent firebase versions you have to use Firebase Cli to connect your app.

Installing the cli first install firebase cli

Firebase CLI via npm by running the following command:

npm install -g firebase-tools

Next, install the FlutterFire CLI by running the following command:

dart pub global activate flutterfire_cli

Once installed, the flutterfire command will be globally available.

In the root of your application, run the configure command:

flutterfire configure

The configuration command will guide you through a number of processes:

  • Selecting a Firebase project (based on the .firebaserc file or from the Firebase Console).
  • Prompt what platforms (e.g. Android, iOS, macOS & web) you would like configuration for.
  • Identify which Firebase applications for the chosen platforms should be used to extract configuration for. By default, the CLI will attempt to automatically match Firebase apps based on your current project configuration.
  • Generate a firebase_options.dart file in your project.

Once complete, you can now import the generated file and provide it to the initializeApp method:
lib/main.dart
// Import the generated file
import 'firebase_options.dart';

Then, provide the current platform options via the currentPlatform getter from the DefaultFirebaseOptions class:


void main() async {
WidgetsFlutterBinding.ensureInitialized();

await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
..

No Firebase App has been created - call Firebase.initializeApp()

If the above answers don't help, you can solve the problem by following steps:

delete the project and take backup of lib folder and pubspec.yaml file.
Create a new project with the same name
copy backed up files to the newly created project.
run flutter pub get
you are good to go

It literally solved my problem. I hope this will help.

Flutter -- No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()

Run flutter clean, then add the dart pub package firebase_core with the command flutter pub add firebase_core. Finally, run flutter pub get to resolve all the dependencies.



Related Topics



Leave a reply



Submit