我的一个功能模块有以下内容:
declare function require(name: string); @NgModule({ imports: [ // other modules here ChartModule.forRoot( require('highcharts'),require('highcharts/highcharts-more'),require('highcharts/modules/funnel'),require('highcharts/modules/heatmap') )
它在本地运行良好,但是当我使用prod标志构建它时它会失败.我得到的错误是:
ERROR in Error encountered resolving symbol values statically. Reference to a non-exported function (position 26
:18 in the original .ts file),resolving symbol ….ERROR in ./src/main.ts
Module not found: Error: Can’t resolve ‘./$$_gendir/app/app.module.ngfactory’ in …
有关如何解决此问题的任何想法?
解决方法
我不能指出你的确切行,因为你没有包含完整的@NgModule装饰器.当你有这样的事情时,这个错误通常在providers数组中:
@NgModule({ // imports,exports and declarations providers: [{ provide: XSRFStrategy,useValue: new CookieXSRFStrategy('RESPONSE_TOKEN','RESPONSE_TOKEN') }] }) export class MyModule {}
当你有这样的内联函数调用时,你不能使用AOT.因此,将useValue替换为useFactory和导出的函数(如错误消息中所述).
这是我第一个上市的AOT安全版本:
export function xsrfFactory() { return new CookieXSRFStrategy('XSRF-TOKEN','X-XSRF-TOKEN'); } @NgModule({ // imports,useFactory: xsrfFactory }] }) export class MyModule {}