3

I'm trying to use AOT compiler in this angular 2 project. I get error: TypeError: this.compiler.compileModules is not a function when I execute command: "node_modules/.bin/ngc" -p tsconfig-aot.json . How to solve this issue?

Steps to reproduce:

  1. clone this repo: https://github.com/AngularClass/angular2-webpack-starter

  2. install compiler-cli (version 2.1.2): npm install @angular/compiler-cli --save

  3. remove src/app/+detail directory and detail router from src/app/app.routes.ts (I did it because "node_modules/.bin/ngc" -p tsconfig-aot.json outputs error: can't resolve module src/app/+detail/index.ts from src/app/+detail/index.ts)

  4. create tsconfig-aot.json:

    { "compilerOptions": { "target": "es5", "module": "es2015", "moduleResolution": "node", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "removeComments": false, "noImplicitAny": true, "suppressImplicitAnyIndexErrors": true },
    "angularCompilerOptions": { "genDir": "aot", "skipMetadataEmit" : true } }

  5. run "node_modules/.bin/ngc" -p tsconfig-aot.json

Amruth
  • 5,792
  • 2
  • 28
  • 41
Ildar
  • 3,808
  • 7
  • 45
  • 81

1 Answers1

5

I just ran into the same issue and resolved it by making sure the "@angular/compiler": "2.1.1" and "@angular/compiler-cli" are using the same version number. e.g. "@angular/compiler-cli" should be "2.1.1" to match the compiler version.

  • yes, the same issue and same solution, it seems @angular/compiler and @angular/compiler-cli shoud strictly be the same version, in my case 2.1.2 – DicBrus Nov 07 '16 at 07:06
  • 3
    And what to do if the same issue is producing in angular@4 – shubham Aug 28 '17 at 12:41