AngularFireModule.initializeApp(...) fails in ng6 prod build
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
angularfire2 @next rc8 :+1 firestore.d.ts : constructor(options: FirebaseOptions, config: FirebaseAppConfig, name: string, shouldEnablePersistence: boolean, settings: Settings, platformId: Object, zone: NgZone);
why 7 arguments ?
Relates to angular/angular#23609
It seems like it's not an issue with us but angular, I'll leave this open for now though so people can find it and incase angular gives us any direction. E.g, we should do something different with our metadata.
@jamesdaniels But why this issue doesn't appear in rc7 but only rc8. The call signature is same. Or I am missing something?
I'm presuming it just has something to do with ng6; but we did change a couple other things since rc7. Namely the addition of AppConfig.
Wait... I might have just thought with something. I did clear out the old overloaded method style as we are using optionals and tslint was complaining about it being unnecessary, maybe that had something to do with it. Let me experiment with that.
There also is some suggestions in the angular issue that seems to solve this for others: comment Maybe that is a hack and isn't the right solution...
Yeah, no dice on that change; I did it before rc7.
I'm having this error too.
My temporary fix ( not recommended ) for now is to make aot and buildOptimizer to false in angular.json
@brijmcq I'd recommend the work-around stated in the issue body in the meantime.
@jymdman Thanks for providing the new way to init the firebase config
To me in Ionic 3 I have that problem as I configure the buildOptimizer.?
What is the current workaround (for now)?
@sarunint As @jymdman wrote:
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 }
],
exports: [],
bootstrap: [AppComponent]
})
export class AppModule {}
FYI #1641 will make this cleaner by making name and appconfig optional.
Sorry, where do I locate the types for the providers? This has them but fails to load as Module does not exist here.
import {
FirebaseOptionsToken,
FirebaseAppNameToken,
FirebaseAppConfigToken
} from "@firebase";import {
FirebaseOptionsToken,
FirebaseAppNameToken,
FirebaseAppConfigToken
} from "@firebase";
@ajonp
import {
AngularFireModule,
FirebaseOptionsToken,
FirebaseAppNameToken,
FirebaseAppConfigToken
} from 'angularfire2';
Humm that throws
message
:
"Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app)."
@ajonp Same here. Getting tired now of firebase constantly breaking my build.
@ajonp @fergalmoran at the providers, just use
{ provide: FirebaseOptionsToken, useValue: environment.firebase }
where ' environment.firebase' is the path to your firebase config!
If you need a AppNameToken or AppConfigToken, you can use the following (replace undefined (default) with the token you want to use)
{ provide: FirebaseAppNameToken, useValue: undefined },
{ provide: FirebaseAppConfigToken, useValue: undefined }
The truth is all very confusing and it is not clear. What was previously used was AngularFireModule.initializeApp and the firebase config file firebaseConfig was kept as indicated by the documentation now where it should be used. And the modules AngularFireDatabaseModule, AngularFireDatabase that are used to access the base are configured or not, because that is what I can not understand yet. Because in a new project only with angularfire2 and adding in the app.module AngularFireDatabaseModule, AngularFireDatabase the command ionic cordova build android --prod --release is still stuck.
import { BrowserModule } from '@angular/platform-browser'; import { ErrorHandler, NgModule } from '@angular/core'; import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular'; import { SplashScreen } from '@ionic-native/splash-screen'; import { StatusBar } from '@ionic-native/status-bar';
import { MyApp } from './app.component'; import { HomePage } from '../pages/home/home';
// import { AngularFireModule } from 'angularfire2'; import { AngularFireDatabaseModule, AngularFireDatabase } from 'angularfire2/database'; import { AngularFireAuthModule } from 'angularfire2/auth';
import { AngularFireModule, FirebaseOptionsToken, FirebaseAppNameToken, FirebaseAppConfigToken } from 'angularfire2';
export const firebaseConfig = { apiKey: "AIzaSyC_t5XQmq4O81BOEIPKqRBXAsEcOoXZJmQ", authDomain: "pencaonline.firebaseapp.com", databaseURL: "https://pencaonline.firebaseio.com", projectId: "pencaonline", storageBucket: "pencaonline.appspot.com", messagingSenderId: "698016836224" };
@NgModule({ declarations: [ MyApp, HomePage ], imports: [ BrowserModule, IonicModule.forRoot(MyApp), AngularFireModule, AngularFireAuthModule, AngularFireDatabaseModule ], bootstrap: [IonicApp], entryComponents: [ MyApp, HomePage ], providers: [ StatusBar, SplashScreen, AngularFireDatabase, { provide: FirebaseOptionsToken, useValue: firebaseConfig }, {provide: ErrorHandler, useClass: IonicErrorHandler} ] }) export class AppModule {}