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

前端 未结 5 1003
心在旅途
心在旅途 2020-12-24 04:11

So I was trying to build and deploy my Angular 4 app for production on both Firebase and Heroku, but I have come across the error as follows:

ERROR in /U

相关标签:
5条回答
  • 2020-12-24 05:06

    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.

    0 讨论(0)
  • 2020-12-24 05:11

    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: "..." }

    0 讨论(0)
  • 2020-12-24 05:12

    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: '...',
      },
    };
    
    0 讨论(0)
  • 2020-12-24 05:14

    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

    0 讨论(0)
  • 2020-12-24 05:14

    Make sure there is no gap between firebase and :.

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

    0 讨论(0)
提交回复
热议问题