我目前正在开发一个Angular6应用程序,经过一段时间的开发,当我试图创建一个Prod构建时
ng build --prod
我遇到了这个错误…
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.
经过一些研究,我已经清楚了这个错误是关于什么以及如何修复它,但是同时,我在
Angular documentation about AOT
以下内容:
从版本5开始,编译器在发出.js文件时自动执行重写。
这意味着什么?通过使用最新版本的Angular和/或Angular CLI包,我得到了上述错误。
我应该以某种方式启用重写吗?
在不重写元数据中的所有lambda的情况下,拥有AOT还是有希望的?
错误中引用的代码是…
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()
}
]
};
正是这条线…
resolveFn: (bootstrapSvc) => bootstrapSvc.initApplication()
如果我将其重写为一个函数并引用其中的函数,那么错误就消失了。像这样的…
bootstrapSvcinitApplicationFunction = function(bootstrapSvc) {
bootstrapSvc.initApplication();
}
...
resolveFn: bootstrapSvcinitApplicationFunction