angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

AngularFireModule.initializeApp(...) fails in ng6 prod build

Open jymdman opened this issue 8 years ago • 34 comments

Version info

Angular: ^6.0.0

Firebase: ^5.0.2

AngularFire: 5.0.0-rc.8.1-next

Other (e.g. Ionic/Cordova, Node, browser, operating system):

How to reproduce these conditions

Failing test unit, Plunkr, or JSFiddle demonstrating the problem

Steps to set up and reproduce

AngularFireModule.initializeApp(....) fails when build with prod:

ERROR in Error during template compile of 'AppModule'
  Function calls are not supported in decorators but 'AngularFireModule' was called.

NgModule looks like:

@NgModule({
  declarations: [AppComponent, LoginComponent],
  entryComponents: [],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule,
    RouterModule.forRoot(APP_ROUTES),
    SharedModule,
    AngularFireModule.initializeApp(environment.firebase, 'stalldata'),
    AngularFirestoreModule,
    AngularFireAuthModule,
    AngularFireStorageModule,
    HomeModule,
    ArtiklarModule,
    MaskinerModule,
    StallbladModule,
    DialogsModule
  ],
  exports: [],
  bootstrap: [AppComponent]
})
export class AppModule {}

Solution is to drop .initializeApp(...) and use providers like this:

@NgModule({
  declarations: [AppComponent, LoginComponent],
  entryComponents: [],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule,
    RouterModule.forRoot(APP_ROUTES),
    SharedModule,
    AngularFireModule,
    AngularFirestoreModule,
    AngularFireAuthModule,
    AngularFireStorageModule,
    HomeModule,
    ArtiklarModule,
    MaskinerModule,
    StallbladModule,
    DialogsModule
  ],
  providers: [
    { provide: FirebaseOptionsToken, useValue: environment.firebase },
    { provide: FirebaseAppNameToken, useValue: 'stalldata' },
    { provide: FirebaseAppConfigToken, useValue: undefined }
  ],
  exports: [],
  bootstrap: [AppComponent]
})
export class AppModule {}

Sample data and security rules

<-- include/attach/link to some json sample data (or provide credentials to a sanitized, test Firebase project) -->

Debug output

** Errors in the JavaScript console **

** Output from firebase.database().enableLogging(true); **

** Screenshots **

Expected behavior

Don't know if this is the expected behavior with rc8? If it is, docs should be updated when rc8 is released to match this. (I can create a fix for this)

Actual behavior

jymdman avatar May 13 '18 09:05 jymdman

@alsit remove AngularFireDatabase from providers array.

And add these 2 object to the providers array.

{ provide: FirebaseAppNameToken, useValue: '[DEFAULT]' },
{ provide: FirebaseAppConfigToken, useValue: undefined }

sarunint avatar May 15 '18 13:05 sarunint

I think the Angular compiler is having trouble analyzing these lines initializeApp.

https://github.com/angular/angularfire2/blob/a8414f5d62ec073db760e0b7e9346e4d946bd3a3/src/core/firebase.app.module.ts#L50-L51

Possible Solution?

Force the second arg to initializeApp to be a FirebaseAppConfig object and remove the string union type, which would also eliminate he need for optional deps. It'd be a breaking change, but minor.

codediodeio avatar May 15 '18 15:05 codediodeio

It works for me when I add just the main provider instead of all of them.

{ provide: FirebaseOptionsToken, useValue: environment.firebase },

tuneis avatar May 16 '18 01:05 tuneis

I get this error when trying to import FirebaseOptionsToken from angularfire2:

Module '"/Users/alexbjorlig/Documents/eddystone/node_modules/angularfire2/index"' has no exported member 'FirebaseOptionsToke

alexbjorlig avatar May 16 '18 06:05 alexbjorlig

Just cut rc.9, which fixes this issue. We've replaced FirebaseAppConfigToken and FirebaseAppNameToken with a new FirebaseNameOrConfigToken which takes a string | FirebaseAppConfig.

Sorry for the breaking change folks, I put a --prod build task in our Travis setup so now we'll be able to catch stuff like this earlier.

Thanks for all your patience and being awesome users!

Btw, to sweeten the deal I got the AngularFireFunctionsModule merged and pushed with rc.9; you should give it a shot ;) Getting FCM support in will be my next priority.

jamesdaniels avatar May 16 '18 15:05 jamesdaniels

thanks

sherinali avatar May 28 '18 21:05 sherinali

Could you describe the solution? I'm having trouble with that line for --aot option....Which are the steps to replace AngularFireModule.initializeApp(environment.firebase) statement? since it's the line is breaking the build

juanlet avatar Jun 11 '18 04:06 juanlet

Update to the latest version of angularfire2, there this issue is fixed

paulstelzer avatar Jun 11 '18 06:06 paulstelzer

I fixed the issue but i had to put angularfire2 initialization in providers array, otherwise it was not fixed....I have the last version

juanlet avatar Jun 11 '18 12:06 juanlet

I can`t solve the problem, please i need help :

ionic 3.20.0 cordova 8.0.0

"firebase": "^5.2.0-0", "angularfire2": "^5.0.0-rc.8.1-next", "promise-polyfill": "^8.0.0",

import { NgModule, ErrorHandler } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular'; import { MyApp } from './app.component';

import { HomePage } from '../pages/home/home'; import { TabsPage } from '../pages/tabs/tabs';

import { AngularFireModule } from 'angularfire2'; import { AngularFireDatabaseModule, AngularFireDatabase } from 'angularfire2/database'; import { AngularFireAuthModule } from 'angularfire2/auth';

//I deleted the firebase data for post here, but this data is setup good in my code export const firebaseConfig = { apiKey: "", authDomain: "", databaseURL: "", projectId: "", storageBucket: "", messagingSenderId: "" };

import { StatusBar } from '@ionic-native/status-bar'; import { SplashScreen } from '@ionic-native/splash-screen';

import { InAppBrowser } from '@ionic-native/in-app-browser';

import { CallNumber } from '@ionic-native/call-number';

import { HttpClientModule } from '@angular/common/http';

import { OneSignal } from '@ionic-native/onesignal';

import { UsuarioSesionService } from '../providers/usuario-sesion';

@NgModule({ declarations: [ MyApp, HomePage, TabsPage ], imports: [ BrowserModule, IonicModule.forRoot(MyApp),

AngularFireModule.initializeApp(firebaseConfig),
AngularFireDatabaseModule,
AngularFireAuthModule,

HttpClientModule,

], bootstrap: [IonicApp], entryComponents: [ MyApp, HomePage, TabsPage ], providers: [ StatusBar, SplashScreen, AngularFireDatabase,

UsuarioSesionService,
InAppBrowser,

CallNumber,
OneSignal,
InAppBrowser,

{provide: ErrorHandler, useClass: IonicErrorHandler}

] }) export class AppModule {}

innovationven avatar Jul 16 '18 17:07 innovationven

@innovationven see https://github.com/angular/angularfire2/issues/1635#issuecomment-389568397

sarunint avatar Jul 16 '18 18:07 sarunint

I did see that comment but the problem is the same, i don`t know what to do

innovationven avatar Jul 16 '18 19:07 innovationven

Just cut rc.9, which fixes this issue. We've replaced FirebaseAppConfigToken and FirebaseAppNameToken with a new FirebaseNameOrConfigToken which takes a string | FirebaseAppConfig.

Please update to rc.9 or greater.

sarunint avatar Jul 17 '18 00:07 sarunint

{ provide: FirebaseOptionsToken, useValue: environment.firebase } fixed my issue

therepo90 avatar Feb 01 '19 09:02 therepo90