Reputation: 785
I'm currently developing an Angular 6 application and after some time developing, when I have tried to create a prod build
ng build --prod
I faced this error...
ERROR in src\app\app.module.ts(26,17): Error during template compile of 'AppModule'
Function expressions are not supported in decorators in 'APP_ROOT_STATE'
'APP_ROOT_STATE' references 'APP_ROOT_STATE'
'APP_ROOT_STATE' contains the error at src\app\app.component.ts(20,16)
Consider changing the function expression into an exported function.
After some research, I have clear what is this error about and how to fix it, but at the same time, I found this statement in the Angular documentation about AOT:
Beginning in version 5, the compiler automatically performs this rewriting while emitting the .js file.
What does this means? I'm getting the error above by using the latest versions of Angular and/or Angular Cli packages.
Should I enable this rewriting somehow? There is some hope of having AOT without rewriting all lambdas in the metadata?
The code which is referenced in the error is this...
export const APP_ROOT_STATE = {
name: 'app',
abstract: true,
views : {
header: { component: CoreUiAppHeaderComponent },
footer: { component: CoreUiAppFooterComponent }
},
onEnter: onEnterStateBreadcrumbHelper(new AppBreadcrumbEntryModel('Home', 'default')),
onExit: onExitStateBreadcrumbHelper(),
resolve: [
{
token: '_appInitialization',
deps: [AppBootstrapService],
resolveFn: (bootstrapSvc) => bootstrapSvc.initApplication()
}
]
};
Exactly this line...
resolveFn: (bootstrapSvc) => bootstrapSvc.initApplication()
If I rewrite this as a function and reference the function there, the error is gone. Something like this...
bootstrapSvcinitApplicationFunction = function(bootstrapSvc) {
bootstrapSvc.initApplication();
}
...
resolveFn: bootstrapSvcinitApplicationFunction
Upvotes: 1
Views: 2154
Reputation: 15261
Most probably angular compiler automatically rewrites only those arrow functions, which are used in component metadata (directives, services etc.), in other words only limited locations are supported. In your case function is located in some other object, so compiler does not know should it rewrite or not.
Upvotes: 2