2017-04-11 41 views
5

我的一個功能模塊有這樣的內容:角4 - 遇到錯誤解析符號值靜態

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') 
) 

它運行在本地正常,但當我與督促標誌構建它失敗。我得到的錯誤是:

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 ...

有關如何解決此問題的任何想法?

+1

我有類似的問題,但隨着出口'const' – KarolDepka

回答

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 {} 
相關問題