angular - 类型 { production : boolean; } 上不存在属性 'firebase'

标签 angular firebase heroku environment-variables firebase-hosting

所以我试图在 Firebase 和 Heroku 上构建和部署我的 Angular 4 应用程序以用于生产,但我遇到了如下错误:

ERROR in /Users/.../... (57,49): Property 'firebase' does not exist on type '{ production: boolean; }'.

当我运行 ng build --prod 并且我的部署服务器运行良好时会发生这种情况。这是我的 app.module.ts 文件,供引用:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabaseModule } from 'angularfire2/database';
import { Ng2ScrollimateModule } from 'ng2-scrollimate';
import { Ng2PageScrollModule } from 'ng2-page-scroll';

import { HttpModule } from '@angular/http';
import { trigger, state, style, animate, transition, keyframes } from '@angular/animations';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { environment } from '../environments/environment';

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

import { LogoComponent } from './logo/logo.component';
import { InfoComponent } from './info/info.component';
import { AboutComponent } from './about/about.component';
import { DividerComponent } from './divider/divider.component';
import { ProficienciesComponent } from './proficiencies/proficiencies.component';
import { ProficiencyComponent } from './proficiency/proficiency.component';
import { PortfolioComponent } from './portfolio/portfolio.component';
import { ProjectComponent } from './project/project.component';
import { ResumeComponent } from './resume/resume.component';
import { FooterComponent } from './footer/footer.component';
import { ContactComponent } from './contact/contact.component';
import { LoadingComponent } from './loading/loading.component';

@NgModule({
  declarations: [
    AppComponent,
    LogoComponent,
    InfoComponent,
    AboutComponent,
    DividerComponent,
    ProficienciesComponent,
    ProficiencyComponent,
    PortfolioComponent,
    ProjectComponent,
    ResumeComponent,
    FooterComponent,
    ContactComponent,
    LoadingComponent,
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    BrowserAnimationsModule,
    AngularFireModule.initializeApp(environment.firebase),
    AngularFireDatabaseModule,
    Ng2ScrollimateModule,
    Ng2PageScrollModule.forRoot(),
  ],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}

environment.prod.ts

export const environment = {
  production: true
};

环境.ts

export const environment = {
  production: true,
  firebase: {
    apiKey: '...',
    authDomain: 'project.firebaseapp.com',
    databaseURL: 'https://project.firebaseio.com',
    projectId: 'project',
    storageBucket: 'project.appspot.com',
    messagingSenderId: '...',
  },
};

在 StackOverflow 和 GitHub 上搜索可能的解决方案后,似乎没有开发人员遇到过这个确切的错误并发布了他们的发现,所以我想知道是否有人知道如何解决这个问题。提前致谢!

最佳答案

当你运行 ng build --prod 时,angular-cli 将使用 environment.prod.ts 文件和你的 environment.prod.ts files environment 变量没有 firebase 字段,因此您会遇到异常。

将字段添加到 environment.prod.ts

export const environment = {
  production: true,
  firebase: {
    apiKey: '...',
    authDomain: 'project.firebaseapp.com',
    databaseURL: 'https://project.firebaseio.com',
    projectId: 'project',
    storageBucket: 'project.appspot.com',
    messagingSenderId: '...',
  },
};

关于angular - 类型 { production : boolean; } 上不存在属性 'firebase',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44033079/

相关文章:

ruby-on-rails - 如何在 Heroku 上使用机架/缓存缓存超过 1MB 的文件?

javascript - 修改 Angular2 服务层的对象 : Subscription is not assignable to the type observable

html - 图像没有从 html 中以 Angular 引用

javascript - 在哪里安全地存储 javascript 发送网格 api key ?

php - curl 错误 77 : error setting certificate verify locations: CAfile

node.js - 静态 Web 应用程序的服务器

javascript - 如何编辑 Chart.js donut ?

javascript - Angular Instagram/Youtube 后退按钮恢复数据和滚动位置

android - 如何使用 kotlin 在 android 中使用 FirebaseRecyclerAdapter 进行编辑文本过滤

python - 如何升级 Heroku 上的分发包?