I developed an Angular library with services to be utilized in various Angular applications. The functionality works smoothly without the --prod flag, indicating it works fine without Ahead-of-Time (AOT) compilation.
However, when generating the library using ng-packagr or other methods like CLI or yeoman generators, I encounter a consistent error every time. Despite experimenting with different Angular versions (5.x.x, 6.x.x & 7.x.x), the same issue arises when invoking LoggerModule.forRoot() in the app.module of the application:
ERROR in Error during template compile of 'AppModule'
Function calls are not supported in decorators but 'LoggerModule' was called.
I have extensively researched this problem and attempted various angularCompilerOptions in tsconfig. Any alternative suggestions from the community would be greatly appreciated. It's crucial for us that the module functions correctly with AOT (Ahead-of-Time) compilation...
NgModule declaration of the library:
@NgModule({
declarations: [],
imports: [],
providers: []
})
export class LoggerModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: LoggerModule,
providers: [LoggerService]
}
}
}
NgModule declaration of the application:
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
LoggerModule.forRoot()
],
providers: [],
bootstrap: [AppComponent],
entryComponents: [AppComponent]
})
export class AppModule {
}