2
votes

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

1

1 Answers

4
votes

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.