【问题标题】:Angular 2 Ahead-of-Time compiler errorAngular 2 Ahead-of-Time 编译器错误
【发布时间】:2017-01-13 10:55:15
【问题描述】:

我在 Windows 7 x64,尝试按照我的 Angular 2 应用程序的 Ahead-of-Time compilation 的说明进行操作。应用程序可以通过即时编译正常编译和运行。

我已经安装了 NPM @angular/compiler-cli@0.6.0 typescript@2.0.2 @angular/platform-server@2.0.0-rc.6@angular/compiler@2.0.0-rc.6

运行ngc时出现以下错误:

C:\websites\learn\angular2>"node_modules/.bin/ngc" -p dev
can't resolve module @angular/core/src/di/opaque_token from C:\...\dev\index.ts
TypeError: undefined is not a function
    at ReflectorHost.findDeclaration (C:\...\node_modules\@angular\compiler-cli\src\reflector_host.js:171:59)
    at StaticReflector.initializeConversionMap (C:\...\node_modules\@angular\compiler-cli\src\static_reflector.js:150:38)
    at new StaticReflector (C:\...\node_modules\@angular\compiler-cli\src\static_reflector.js:42:14)
    at Function.CodeGenerator.create (C:\...\node_modules\@angular\compiler-cli\src\codegen.js:142:31)
    at codegen (C:\...\node_modules\@angular\compiler-cli\src\main.js:7:36)
    at Object.main (C:\...\node_modules\@angular\tsc-wrapped\src\main.js:30:16)
    at Object.<anonymous> (C:\...\node_modules\@angular\compiler-cli\src\main.js:14:9)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
Compilation failed

这是我的文件夹结构(tsconfig.json 在顶级angular2 中):

乍一看,错误似乎是similar to this one,但仔细一看,我的(“undefined is not a function”)就不一样了。有什么想法吗?

【问题讨论】:

  • 嘿@GünterZöchbauer。在发布之前,我查看了该问题。在这种情况下,ngc 实际上能够运行。它只是不会产生预期的文件;它输出.js.js.map.json 文件而不是.ngfactory.ts。就我而言,ngc 崩溃时没有输出任何内容

标签: angular deployment


【解决方案1】:

这与我安装的节点版本有关。

$ node --version
v0.12.7

$ npm --version
3.7.5

在我从 https://nodejs.org/en/download/ 下载并安装最新的 64 位 .msi 安装程序后:

$ node --version
v4.5.0

$ npm --version
2.15.9

错误不再发生

【讨论】:

  • 我正在使用 node v6.2.2 和 npm v3.9.5,但我仍然收到此错误
  • @brando 我也遇到了同样的错误。你能解决吗?
猜你喜欢
  • 2017-05-03
  • 2017-01-13
  • 1970-01-01
  • 1970-01-01
  • 2017-01-15
  • 1970-01-01
  • 2023-03-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多