角度AOT构建:内部错误:未知标识undefined

角度AOT构建:内部错误:未知标识undefined

问题描述:

我的当前角度项目在角度前开始支持AOT功能。现在我试图让它工作。我收到以下错误,我不知道这意味着什么,我可以开始调试问题。有没有人知道为什么会出现这个错误?角度AOT构建:内部错误:未知标识undefined

依赖

"@angular/animations": "^4.4.4", 
"@angular/common": "^4.4.4", 
"@angular/compiler": "^4.4.4", 
"@angular/core": "^4.4.4", 
"@angular/forms": "^4.4.4", 
"@angular/platform-browser": "^4.4.4", 
"@angular/platform-browser-dynamic": "^4.4.4", 
"@angular/router": "^4.4.4", 
"@ngx-translate/core": "^8.0.0", 
"@ngx-translate/http-loader": "^2.0.0", 
"core-js": "^2.5.1", 
"font-awesome": "^4.7.0", 
"primeng": "^4.2.1", 
"quill": "^1.3.2", 
"rxjs": "^5.4.3", 
"zone.js": "^0.8.18" 

错误

ERROR in Error: Internal error: unknown identifier undefined 
at Object.importExpr$$1 [as importExpr] (...\node_modules\@angular\compiler\bundles\compiler.umd.js:24211:23) 
at tokenExpr (...\node_modules\@angular\compiler\bundles\compiler.umd.js:18577:39) 
at providerDef (...\node_modules\@angular\compiler\bundles\compiler.umd.js:18480:20) 
at ...\node_modules\@angular\compiler\bundles\compiler.umd.js:18697:77 
at Array.map (<anonymous>) 
at NgModuleCompiler.compile (...\node_modules\@angular\compiler\bundles\compiler.umd.js:18697:44) 
at AotCompiler._compileModule (...\node_modules\@angular\compiler\bundles\compiler.umd.js:24144:32) 
at ...\node_modules\@angular\compiler\bundles\compiler.umd.js:24056:66 
at Array.forEach (<anonymous>) 
at AotCompiler._compileImplFile (...\node_modules\@angular\compiler\bundles\compiler.umd.js:24056:19) 
at ...\node_modules\@angular\compiler\bundles\compiler.umd.js:23969:87 
at Array.map (<anonymous>) 
at AotCompiler.emitAllImpls (...\node_modules\@angular\compiler\bundles\compiler.umd.js:23969:52) 
at CodeGenerator.emit (...\node_modules\@angular\compiler-cli\src\codegen.js:42:46) 
at ...\node_modules\@angular\compiler-cli\src\codegen.js:33:61 
at <anonymous> 
at process._tickCallback (internal/process/next_tick.js:188:7) 

应用程序的这部分导致了问题的模板变量:

export function windowFactory(): any { 
    return window; 
} 

providers: [{ 
    provide: Window, 
    useFactory: windowFactory 
}], 

Github: This fails with AoT compiler in Angular CLI, because Window (the browser window) is an interface

+0

嗨,你做了什么来修复提供商的工厂? – Cristiano

+1

@Injectable() 出口类WindowWrapper延伸窗口{ } 导出功能getWindow(){ \t返回窗口; } – im4ever

检查模板,也许你使用未在组件中定义

尝试提供注射日期而不是注射标记时有相同的错误。

所以我做:

providers: [ { provide: Date, useValue: new Date() } ]

,并把它改成

providers: [ { provide: NOW, useValue: new Date() }, ],

其中NOW是依赖于像这样

export const NOW = new InjectionToken<Date>('now');

服务定义10

所有记录在Angular site