【问题标题】:Typescript 2.1 coupled with the Angular 2 compiler silently fails to compile project files (no output)Typescript 2.1 与 Angular 2 编译器相结合,无法编译项目文件(无输出)
【发布时间】:2017-03-11 14:35:09
【问题描述】:

使用以下打字稿和角度编译器配置:

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noEmitHelpers": true,
    "skipDefaultLibCheck": true,
    "strictNullChecks": false,
    "outDir": "tmp"
  },
  "exclude": [
    "node_modules",
    "compiled",
    "app/main.ts"
  ],
  "angularCompilerOptions": {
    "genDir": "compiled",
    "skipMetadataEmit" : true
  }
}

/compiled 目录仅包含 /node_modules/@angular,而缺少所需 ngfactory 文件的 /app 目录。编译以静默方式结束,没有错误也没有输出。

它在 Typescript 2.0 上工作得很好,但我想在针对 es5 时使用 2.1 来支持 async/await,从而消除使用 babel 的额外编译步骤。

[编辑]

这只发生在Typescript 2.1.0-dev.20160907 之后,也就是实现异步/等待支持的时候。我猜这是该版本中破坏ngc 的更改之一; 2.1.0-dev.20160906 仍然有效。

[编辑2]

如果有人尝试将ngc 与 typescript 2.1 一起使用,如果它适合您,您能否留下简短的评论?这至少可以告诉我问题是否与我的配置有关。

【问题讨论】:

  • 我不是 Typescript 方面的专家,但我记得看到 outDir 对 Angular 2 产生了奇怪的影响;你在tmp 目录中看到了什么样的输出?
  • tmp 目录包含来自app 的已编译(js + map)文件。没有outDir 选项的行为相同,compiled 没有任何应用程序文件,只有 node_modules。
  • 昨天我在使用 Typescript 2.1 和 Angular 2.3.0 时遇到了同样的问题,但没有在我的 tsconfig.json 中指定 outDir。切换回 2.0.x Typescript 是可行的,所以据我所知,这不是 Angular 的错。
  • Jit 编译似乎工作正常。我认为问题在于 AoT 编译,具体可能是ngc

标签: angular typescript angular2-compiler


【解决方案1】:

问题源于 v2.1 中 typescript 的一些内部更改,这些更改未在 angular tsc-wrapper 中解决。

在这个pull request 中得到了修复。合并后,文件应该会再次正常编译。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-17
    • 1970-01-01
    • 1970-01-01
    • 2022-09-25
    • 2016-04-02
    • 2012-11-08
    • 2016-12-13
    • 2017-12-09
    相关资源
    最近更新 更多