Property 'firebase' does not exist on type { production: boolean; }

丶灬走出姿态 提交于 2019-11-28 18:33:33
eko

When you run ng build --prod angular-cli will use the environment.prod.ts file and your environment.prod.ts files environment variable doesn't have the firebase field hence you are getting the exception.

Add the field to 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: "..."
  }
};

My approach is to merge common environment object with prod one. Here's my environment.prod.ts:

import { environment as common } from './environment';

export const environment = {
  ...common,
  production: true
};

So common environment object acts as an overridable default for all other environments.

I hate duplicates in code
so let's create a separate file named environments/firebase.ts with content

export const firebase = {
    //...
};

the usage

import {firebase} from '../environments/firebase';
//...
AngularFireModule.initializeApp(firebase)

all is clear as for me

I got the same error because I had misspelled 'firebase' as 'firebas'

firebas: { apiKey: "...", authDomain: "project.firebaseapp.com", databaseURL: "https://project.firebaseio.com", projectId: "project", storageBucket: "project.appspot.com", messagingSenderId: "..." }

Neelesh Ahankari

Make sure there is no gap between firebase and :.

That is, it should be firebase:, not firebase :.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!