【问题标题】:Firebase returns "app/bad-app-name" in angularfire2Firebase 在 angularfire2 中返回“app/bad-app-name”
【发布时间】:2018-10-26 10:17:42
【问题描述】:

在我的 Angular 应用程序中,Firebase 返回一个错误,将 bad-app-name 显示为代码。 我在 Angular 应用程序中使用 angularfire2。

我仔细检查了Firebase的配置,没问题,请问如何解决这个错误。

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 { }

控制台错误

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

【问题讨论】:

  • 您的项目/应用在 Firebase 中的名称是什么?正如您在相应项目/应用卡的第一行的 Firebase 控制台中看到的那样?
  • 尝试执行类似AngularFireModule.initializeApp(firebaseConfig, 'some-app-name') 的操作,看看是否会遇到同样的错误。
  • 我已经尝试过@AlexanderStaroselsky
  • 您使用的是哪个版本的 firebase + angularfire?

标签: javascript angular firebase angularfire2


【解决方案1】:

要解决这个问题,

第 1 步:使用以下命令卸载

npm uninstall --save firebase

第 2 步:现在,打开您的 package.json 文件。在那里,你会发现:

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

第 3 步: 在此行下方,添加此行(不带 Caret(^) 符号):并保存

"firebase": "4.8.0"

第 4 步: 现在进行 npm 安装。您的应用应该可以运行

【讨论】:

    【解决方案2】:

    对我有用的解决方案:

    npm uninstall --save firebase angularfire2
    

    然后

    npm install angularfire2 firebase --save
    

    【讨论】:

      【解决方案3】:
      • npm uninstall --save firebase。
      • 在你的 package.json 中:
      "angularfire2": "^5.0.0-rc.7",
      "firebase": "4.12.1"
      
      • npm 我

      【讨论】:

        【解决方案4】:

        我刚刚遇到同样的错误。我通过确保 "@firebase/app": "^0.3.3", 依赖是最新的。

        【讨论】:

        • 谢谢! "@firebase/app": "^0.3.4""@angular/fire": "^5.0.2" 一起为我工作
        猜你喜欢
        • 2019-02-18
        • 1970-01-01
        • 2021-11-08
        • 2018-08-06
        • 2021-07-23
        • 2022-01-21
        • 1970-01-01
        • 2021-07-29
        • 2021-05-13
        相关资源
        最近更新 更多