3

Does anyone know how to get more detailed error stack trace while using Angular CLI with AOT compiling? There's no issue in my app when running with JIT compilation but when I run ng build --aot all I get is: TypeError: Cannot read property "length" of undefined. There's no info where's the source of error. I suppose there's some issue in one of my templates but I don't have idea which one is the problem.

I'm using latest versions of Angular CLI (1.0.0-beta.24) and Angular 2 (2.4.1).

EDIT

Here's the full message from the compilator while using ng serve --aot command:

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
3
  • should post some codes.. how "length" of variable do you have ? Commented Jan 4, 2017 at 21:34
  • The application is quite complex. It has hundreds of templates and corresponding .ts files so unfortunately it's impossible to post the code. While developing in JIT compilation that kind of error ("Cannot read property "length"...) usually ocurred when I was trying to loop with *ngFor directive through uninitialized variable or empty array. But, as I mentioned, there's no such error with JIT compilation. Maybe it's possible to put something in tsconfig.json that'll force compiler to show full stack trace for errors like that? Commented Jan 4, 2017 at 21:46
  • afaik beta.24 is supposed to work with angular 2.3.1 Commented Jan 5, 2017 at 1:53

2 Answers 2

1

also had this error message using the AOT compiler. In my case, it was a problem with a token in the providers configuration of the app module that didn't work with AOT. See https://www.bennadel.com/blog/3138-creating-a-custom-errorhandler-in-angular-2-rc-6.htm?&_=0.39111966827042277#comments_48858

Sign up to request clarification or add additional context in comments.

Comments

0

I've had this before and it can be a real pain. Have you tried ng serve --aot and looking at the stack trace in the browser?

I've narrowed down these issues in the past by removing code incrementally using a binary search strategy :/

1 Comment

I've added error message from the browser (while using ng serve --aot).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.