我正在尝试使用 AOT编译器 this Angular 2项目。我得到错误: TypeError: this.compiler.compileModules
is not a function when I execute command: "node_modules/.bin/ngc"-p tsconfig-aot.json
。
如何解决这个问题?
重现步骤:
克隆此存储库:https://github.com/AngularClass/angular2-webpack-starter
安装 compiler-cli(版本 2.1.2):npm install @angular/compiler-cli --save
从
src/app/app.routes.ts
中删除src/app/+detail
目录和detail
路由器(我这样做是因为"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
)创建
tsconfig-aot.json
:{ “编译器选项”:{ “目标”:“ES5”, “模块”:“es2015”, "moduleResolution": "节点", “源 map ”:真实的, “emitDecoratorMetadata”:真实的, “experimentalDecorators”:真实的, “删除评论”:假的, “noImplicitAny”:是的, "suppressImplicitAnyIndexErrors": true },
“angularCompilerOptions”:{ "genDir": "aot", “skipMetadataEmit”:真 }运行
"node_modules/.bin/ngc"-p tsconfig-aot.json
最佳答案
我刚刚遇到了同样的问题,并通过确保 "@angular/compiler": "2.1.1"和 "@angular/compiler-cli"使用相同的版本号来解决它。例如“@angular/compiler-cli”应为“2.1.1”以匹配编译器版本。
关于angular - Angular 2 提前编译中的未知编译器选项 'angularCompilerOptions',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40407132/