Firebase returns “app/bad-app-name” in angularfire

2019-06-24 15:10发布

In my Angular app Firebase returns an error which shows bad-app-name as code. i'm using angularfire2 in angular app.

I have double checked Firebase configuration, it is alright, so how to solve this error.

app.components.ts

import { Component, OnInit } from '@angular/core';
import { FormsModule, NgForm } from "@angular/forms";
import { AngularFireDatabase } from "angularfire2/database";
import { Router } from '@angular/router';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent{
  isLoggedIn: boolean = false;
  courses: any[];
  constructor(public db: AngularFireDatabase) {
    db.list('/Courses').valueChanges().subscribe(courses => {
      this.courses = courses;
      console.log(this.courses);
    });
  }

  login() {
    this.isLoggedIn = !this.isLoggedIn;
  }
  user:any;
  saveData(formData) {
    if (formData.valid) {
      console.log(formData.value);
    }
  }
}

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { HttpModule } from "@angular/http";
import { AppRoutingModule } from './app-routing.module';

import { AngularFireModule } from "angularfire2";
import { AngularFireDatabaseModule } from "angularfire2/database";
import { AngularFireAuthModule } from "angularfire2/auth";

import { AppComponent } from './app.component';

export const firebaseConfig = {
  apiKey: "apikey",
  authDomain: "angular-f5fa9.firebaseapp.com",
  databaseURL: "https://angular-f5fa9.firebaseio.com",
  projectId: "angular-f5fa9",
  storageBucket: "angular-f5fa9.appspot.com",
  messagingSenderId: "592083773091"
};

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    AngularFireModule.initializeApp(firebaseConfig),
    AngularFireDatabaseModule,
    AngularFireAuthModule,
    FormsModule,
    ReactiveFormsModule,
    HttpModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Console Error

FirebaseError {
code: "app/bad-app-name", 
message: "Firebase: Illegal App name: '[object Object] (app/bad-app-name).", 
name: "[object Object]", 
ngDebugContext: DebugContext_, 
ngErrorLogger: ƒ, …}

4条回答
地球回转人心会变
2楼-- · 2019-06-24 15:43

Solution which worked for me :

npm uninstall --save firebase angularfire2

Then

npm install angularfire2 firebase --save
查看更多
Deceive 欺骗
3楼-- · 2019-06-24 15:43

I just struggled with the same error. I resolved it by making sure the "@firebase/app": "^0.3.3", dependency was up to date.

查看更多
男人必须洒脱
4楼-- · 2019-06-24 15:45

To fix this one,

Step 1: Uninstall with the following command

npm uninstall --save firebase

Step 2: Now, open your package.json file. There, you will find:

"angularfire2": "^5.0.0-rc.4"

Step 3: Below this line, add a this line (without the Caret(^) symbol): and save

"firebase": "4.8.0"

Step 4: Now do an npm install. Your app should work

查看更多
劳资没心,怎么记你
5楼-- · 2019-06-24 15:46
  • npm uninstall --save firebase.
  • In your package.json:
"angularfire2": "^5.0.0-rc.7",
"firebase": "4.12.1"
  • npm i
查看更多
登录 后发表回答