kinkaz kinkaz - 1 month ago 31
TypeScript Question

Angular AOT compilation failed

I need to put a website in production soon and am looking into the AOT to improve performance (my app needs about 3-4 secs to load on Chrome, 8-10 secs on Firefox, which is just not possible for production).

I followed the guide on https://angular.io/docs/ts/latest/cookbook/aot-compiler.html but am stuck with the compiling part...

If I type : node_modules/.bin/ngc -p tsconfig-aot.json I will get a nice "Compilation failed" with a list of around 100 hundred errors, like this one :

Error at /myapp/aot/app/contact/admin/contact-list.component.ngfactory.ts:64:7: Supplied parameters do not match any signature of call target.


I am not able to solve all of them, as some are coming from Angular directly (I guess), for example :

Error at /myapp/node_modules/@angular/core/src/di/reflective_provider.d.ts:88:165: Cannot find name 'Map'.


Is the compilation failed related to all these errors and if I solve them the compilation will pass ? If yes, is it normal that even Angular causes errors such as the one I provided ?

Thanks !

Note : I am using Angular 2.1.1.

Answer

For those who are interested :

The compiler will fail if you have Typescript errors (even if you forgot to type a variable, for example myVar = 6 will throw an error, myVar: any = 6 will pass).

The angular errors shouldn't be appearing and it has been solved for me by adding this dependency in my package.json :

"@types/core-js": "^0.9.34"