开发者问题收集

Angular-CLI AOT - 错误堆栈跟踪

2017-01-04
2204

有人知道如何在使用 Angular CLI 进行 AOT 编译时获取更详细的错误堆栈跟踪吗?使用 JIT 编译运行时,我的应用程序没有问题,但是当我运行 ng build --aot 时,我得到的只是: TypeError:无法读取未定义的属性“length” 。没有关于错误来源的信息。我想我的某个模板中存在一些问题,但我不知道哪一个是问题所在。

我正在使用最新版本的 Angular CLI (1.0.0-beta.24) 和 Angular 2 (2.4.1)。

编辑

这是使用 ng serve --aot 命令时来自编译器的完整消息:

Cannot read property 'length' of undefined

./app/main.ts
Module not found: Error: Can't resolve './$$_gendir/app.module.ngfactory' in 'C:\frontend-angular-cli\app'
resolve './$$_gendir/app.module.ngfactory' in 'C:\frontend-angular-cli\app'
using description file: C:\frontend-angular-cli\package.json (relative path: ./app)
Field 'browser' doesn't contain a valid alias configuration
after using description file: C:\frontend-angular-cli\package.json (relative path: ./app)
using description file: C:\frontend-angular-cli\package.json (relative path: ./app/$$_gendir/app.module.ngfactory)
as directory
C:\frontend-angular-cli\app\$$_gendir\app.module.ngfactory doesn't exist
no extension
Field 'browser' doesn't contain a valid alias configuration
C:\frontend-angular-cli\app\$$_gendir\app.module.ngfactory doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
C:\frontend-angular-cli\app\$$_gendir\app.module.ngfactory.ts doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
C:\frontend-angular-cli\app\$$_gendir\app.module.ngfactory.js doesn't exist
[C:\frontend-angular-cli\app\$$_gendir\app.module.ngfactory]
[C:\frontend-angular-cli\app\$$_gendir\app.module.ngfactory]
[C:\frontend-angular-cli\app\$$_gendir\app.module.ngfactory.ts]
[C:\frontend-angular-cli\app\$$_gendir\app.module.ngfactory.js]
@ ./app/main.ts 8:0-70
@ multi main

./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
Module not found: Error: Can't resolve 'C:\frontend-angular-cli\app\$$_gendir' in 'C:\frontend-angular-cli\node_modules\@angular\core\src\linker'
resolve 'C:\frontend-angular-cli\app\$$_gendir' in 'C:\frontend-angular-cli\node_modules\@angular\core\src\linker'
using description file: C:\frontend-angular-cli\node_modules\@angular\core\package.json (relative path: ./src/linker)
Field 'browser' doesn't contain a valid alias configuration
after using description file: C:\frontend-angular-cli\node_modules\@angular\core\package.json (relative path: ./src/linker)
using description file: C:\frontend-angular-cli\package.json (relative path: ./app/$$_gendir)
as directory
C:\frontend-angular-cli\app\$$_gendir doesn't exist
[C:\frontend-angular-cli\app\$$_gendir]
@ ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js 69:15-36 85:15-102
@ ./~/@angular/core/src/linker.js
@ ./~/@angular/core/src/core.js
@ ./~/@angular/core/index.js
@ ./app/main.ts
@ multi main
2个回答

使用 AOT 编译器时也出现了此错误消息。就我而言,这是由于应用程序模块的提供程序配置中的令牌存在问题,该令牌无法与 AOT 配合使用。请参阅 https://www.bennadel.com/blog/3138-creating-a-custom-errorhandler-in-angular-2-rc-6.htm?&_=0.39111966827042277#comments_48858

Marc
2017-01-16

我以前遇到过这种情况,这真的很麻烦。你试过 ng serve --aot 并在浏览器中查看堆栈跟踪吗?

过去,我通过使用二分搜索策略逐步删除代码来缩小这些问题的范围 :/

shusson
2017-01-05