我试图在这个angular 2项目中使用AOT编译器。当我执行命令:"node_modules/.bin/ngc" -p tsconfig-aot.json
时,我得到错误:TypeError: this.compiler.compileModules
不是一个函数。如何解决这个问题?
复制步骤:
-
克隆这个仓库:https://github.com/AngularClass/angular2-webpack-starter
-
install compiler-cli (version 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
输出错误:can't resolve module src/app/+detail/index.ts from src/app/+detail/index.ts
) -
create
tsconfig-aot.json
:{" compilerOptions ": {"目标":"es5","模块":"es2015","moduleResolution":"节点","sourceMap":没错,"emitDecoratorMetadata":没错,"experimentalDecorators":没错,"removeComments":假的,"noImplicitAny":没错,"suppressImplicitAnyIndexErrors":真的},
" angularCompilerOptions ": {:"genDir aot","skipMetadataEmit": true}} -
run
"node_modules/.bin/ngc" -p tsconfig-aot.json
我刚刚遇到了同样的问题,并通过确保"@angular/compiler": "2.1.1"one_answers"@angular/compiler-cli"使用相同的版本号来解决它。如。"@angular/compiler-cli"应该是"2.1.1",以匹配编译器的版本。