Skip to content

[Feature request] Better stack on compilation errors DX (AOT) #5343

Closed
@soyuka

Description

@soyuka

OS?

Linux Debian Jessie

Versions.

@angular/cli: local (v1.0.0-rc.1, branch: master)
node: 6.10.0
os: linux x64
@angular/common: 2.4.9
@angular/compiler: 2.4.9
@angular/core: 2.4.9
@angular/forms: 2.4.9
@angular/http: 2.4.9
@angular/platform-browser: 2.4.9
@angular/platform-browser-dynamic: 2.4.9
@angular/router: 3.4.9
@angular/cli: 1.0.0-rc.1
@angular/compiler-cli: 2.4.9

Repro steps.

Put something like this in the code (honest mistake, perfect valid typescript/javascript):

import { SomeClass } from 'somemodule'

const c = new SomeClass

The log given by the failure.

ng build # no errors
ng build --aot 

....

ERROR in Cannot read property 'map' of undefined

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/root.module.ngfactory' in '/.../client/src'
 @ ./src/main.ts 4:0-76
 @ multi ./src/main.ts

Now this error Cannot read property 'map' of undefined really doesn't help. I had to edit packages/@angular/cli/tasks/build.ts:

--- a/packages/@angular/cli/tasks/build.ts
+++ b/packages/@angular/cli/tasks/build.ts
@@ -35,6 +35,7 @@ export default Task.extend({

     return new Promise((resolve, reject) => {
       const callback: webpack.compiler.CompilerCallback = (err, stats) => {
+        console.log(stats.compilation.errors)
         if (err) {
           return reject(err);
         }

This gave me the full stack:

TypeError: Cannot read property 'map' of undefined
      at Evaluator.evaluateNode (/home/abluchet/angular-cli/node_modules/@angular/tsc-wrapped/src/evaluator.js:302:54)

This was actually helpful because it helped me to figure out that it came from a ts.SyntaxKind.NewExpression that had no .arguments.

With that I was able to figure out the class name that errored and could grep and fix the problem, which was only that constructors need parenthesis to be valid in angular typescript wrapper...

Fixed code:

import { SomeClass } from 'somemodule'

const c = new SomeClass() // <= parenthesis

Could we get better stack for AOT compilations errors? It's just like the many reported error cannot read length of undefined or unclear other random errors that would be pretty easy to fix with proper stack (ie less noob issues here).

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions