【问题标题】:Unknown compiler option 'angularCompilerOptions' in angular 2 ahead-of-time compilationAngular 2 提前编译中的未知编译器选项“angularCompilerOptions”
【发布时间】:2017-03-17 08:53:01
【问题描述】:

我正在尝试在this angular 2 项目中使用AOT 编译器。我收到错误:TypeError: this.compiler.compileModules is not a function 当我执行命令时:"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:

    { “编译器选项”:{ “目标”:“es5”, “模块”:“es2015”, "moduleResolution": "节点", “源地图”:是的, “emitDecoratorMetadata”:真, “experimentalDecorators”:是的, “删除评论”:假, “noImplicitAny”:是的, “suppressImplicitAnyIndexErrors”:真 },
    “角编译器选项”:{ "genDir": "aot", “skipMetadataEmit”:真 } }

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

【问题讨论】:

    标签: angular angular2-cli angular2-compiler


    【解决方案1】:

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

    【讨论】:

    • 是的,同样的问题和同样的解决方案,似乎@angular/compiler 和@angular/compiler-cli 应该是同一个版本,在我的例子中是2.1.2
    • 如果在 angular@4 中出现同样的问题该怎么办
    猜你喜欢
    • 2021-07-14
    • 2021-12-29
    • 2018-05-27
    • 1970-01-01
    • 2019-10-07
    • 1970-01-01
    • 1970-01-01
    • 2016-12-20
    • 2021-06-09
    相关资源
    最近更新 更多