【问题标题】:Angular 4 - Error encountered resolving symbol values staticallyAngular 4 - 静态解析符号值时遇到错误
【发布时间】:2017-09-06 17:39:23
【问题描述】:

我的一个功能模块有这样的内容:

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 标志构建它时它失败了。我得到的错误是:

错误中的错误遇到静态解析符号值。引用非导出函数(位置 26 :18 在原始 .ts 文件中),解析符号 ....

./src/main.ts 中的错误 未找到模块:错误:无法解析 './$$_gendir/app/app.module.ngfactory' in ...

知道如何解决这个问题吗?

【问题讨论】:

  • 我也有类似的问题,但是export const
  • @NgModule 下的.forRoot(aVariable) 调用中遇到类似问题,其中aVariable 是由一系列函数调用计算的 - 必须export 所有函数参与该调用链 (function -> export function) 以解决问题

标签: angular build angular2-aot


【解决方案1】:

我无法指出确切的行,因为您没有包含完整的 @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, exports and declarations
  providers: [{
    provide: XSRFStrategy,
    useFactory: xsrfFactory
  }]
})
export class MyModule {}

【讨论】:

    猜你喜欢
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 2018-01-03
    • 1970-01-01
    • 2017-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多