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

标签 angular angular2-cli angular2-compiler

我正在尝试使用 AOT编译器 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 outputs error: can't resolve module src/app/+detail/index.ts from src/app/+detail/index.ts)

  4. 创建 tsconfig-aot.json:

    { “编译器选项”:{ “目标”:“ES5”, “模块”:“es2015”, "moduleResolution": "节点", “源 map ”:真实的, “emitDecoratorMetadata”:真实的, “experimentalDecorators”:真实的, “删除评论”:假的, “noImplicitAny”:是的, "suppressImplicitAnyIndexErrors": true },
    “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”以匹配编译器版本。

关于angular - Angular 2 提前编译中的未知编译器选项 'angularCompilerOptions',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40407132/

相关文章:

angular - 在angular2中动态加载HTML模板

angular - 如何使用/创建动态模板来使用 Angular 2.0 编译动态组件?

angular - 在 Angular 中将路由集中到服务中

javascript - Angular2鼠标右键双击

asynchronous - 立即解决 Observable - 相当于 $q.when()

javascript - 语法错误 - typescript - 意外标记 :?

Angular 9 + CLI (TypeScript) - 如何停止生成 .spec.ts 测试文件

angular - 如何在 Angular 2 中使用窗口对象?