angular 2 提前编译中的未知编译器选项 'angularCompilerOptions'

Unknown compiler option 'angularCompilerOptions' in angular 2 ahead-of-time compilation

我正在尝试使用 AOT compiler in this angular 2 个项目。我收到错误: TypeError: this.compiler.compileModules is not a function when I execute command: "node_modules/.bin/ngc" -p tsconfig-aot.json 。 如何解决这个问题?

重现步骤:

  1. 克隆此存储库:https://github.com/AngularClass/angular2-webpack-starter

  2. 安装 compiler-cli(版本 2.1.2):npm install @angular/compiler-cli --save

  3. src/app/app.routes.ts删除src/app/+detail目录和detail路由器(我这样做是因为"node_modules/.bin/ngc" -p tsconfig-aot.json输出错误:can't resolve module src/app/+detail/index.ts from src/app/+detail/index.ts

  4. 创建tsconfig-aot.json:

    { "compilerOptions":{ "target": "es5", "module": "es2015", "moduleResolution": "node", "sourceMap": 是的, "emitDecoratorMetadata":是的, "experimentalDecorators": 是的, "removeComments":错误, "noImplicitAny": 是的, "suppressImplicitAnyIndexErrors":真 },
    "angularCompilerOptions":{ "genDir": "aot", "skipMetadataEmit":正确 } }

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

我只是 运行 遇到了同样的问题,并通过确保 "@angular/compiler": "2.1.1" 和 "@angular/compiler-cli" 正在使用来解决它相同的版本号。例如“@angular/compiler-cli”应为“2.1.1”以匹配编译器版本。