【问题标题】:Angular-CLI AOT - error stack traceAngular-CLI AOT - 错误堆栈跟踪
【发布时间】:2017-05-19 07:11:26
【问题描述】:

有谁知道在使用 Angular CLI 和 AOT 编译时如何获得更详细的错误堆栈跟踪?使用 JIT 编译运行时,我的应用程序没有问题,但是当我运行 ng build --aot 时,我得到的只是:TypeError: Cannot read property "length" of undefined。没有信息哪里是错误的来源。我想我的一个模板中存在一些问题,但我不知道哪一个是问题。

我正在使用最新版本的 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

【问题讨论】:

  • 应该发布一些代码..变量的“长度”如何?
  • 应用程序相当复杂。它有数百个模板和相应的 .ts 文件,因此很遗憾无法发布代码。在 JIT 编译中开发时,当我尝试通过未初始化的变量或空数组使用 *ngFor 指令循环时,通常会发生这种错误(“无法读取属性“长度”...)。但是,正如我所提到的,没有这样的错误使用 JIT 编译。也许可以在 tsconfig.json 中放置一些东西,这会强制编译器显示完整的堆栈跟踪以显示此类错误?
  • afaik beta.24 应该适用于 Angular 2.3.1

标签: angular angular-cli angular2-aot


【解决方案1】:

使用 AOT 编译器也有此错误消息。在我的情况下,这是一个不适用于 AOT 的应用程序模块的提供程序配置中的令牌问题。见https://www.bennadel.com/blog/3138-creating-a-custom-errorhandler-in-angular-2-rc-6.htm?&_=0.39111966827042277#comments_48858

【讨论】:

    【解决方案2】:

    我以前有过这种情况,这可能是一种真正的痛苦。您是否尝试过ng serve --aot 并查看浏览器中的堆栈跟踪?

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

    【讨论】:

    • 我添加了来自浏览器的错误消息(使用ng serve --aot时)。
    猜你喜欢
    • 2018-09-19
    • 1970-01-01
    • 1970-01-01
    • 2017-06-25
    • 2016-06-21
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多