Angular 2 - AoT编译器

时间:2016-11-28 07:52:22

标签: angular typescript aot

我正在学习Angular 2,遵循https://angular.io/docs/ts/latest/cookbook/aot-compiler.html

并使用此命令编译我的应用程序。

"node_modules/.bin/ngc" -p tsconfig-aot.json

但是,我只生成了node_modules,而不是我的应用程序。 enter image description here

看来这是一个问题,你能帮助解决另一种解决方案吗?

这是tsconfig-aot.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "moduleResolution": "node",
    "outDir": "./aot",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [ "es2015", "dom" ],
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true,
    "types": []
  },

  "files": [
    "app/app.module.ts",
    "app/main.ts"
  ],

  "angularCompilerOptions": {
    "genDir": "./aot",
    "skipMetadataEmit": true
  }
}

//https://github.com/angular/angular/issues/11689

和package.json

{
  "name": "angular2-quickstart",
  "version": "1.0.0",
  "scripts": {
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
    "lite": "lite-server",
    "postinstall": "typings install",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings"
  },
  "license": "ISC",
  "dependencies": {
    "@angular/common": "^2.2.3",
    "@angular/compiler": "^2.2.3",
    "@angular/compiler-cli": "^2.2.3",
    "@angular/core": "^2.2.3",
    "@angular/forms": "^2.2.3",
    "@angular/http": "^2.2.3",
    "@angular/platform-browser": "^2.2.3",
    "@angular/platform-browser-dynamic": "^2.2.3",
    "@angular/platform-server": "^2.2.3",
    "@angular/router": "^3.2.3",
    "@angular/upgrade": "^2.2.3",
    "bootstrap": "^3.3.6",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.3",
    "rxjs": "^5.0.0-rc.4",
    "systemjs": "^0.19.41",
    "typescript": "^2.0.10",
    "typings": "^1.5.0",
    "zone.js": "^0.6.23"
  },
  "devDependencies": {
    "concurrently": "^2.2.0",
    "lite-server": "^2.2.2",
    "typescript": "^2.0.2",
    "typings": "^1.3.2"
  }
}

编辑:我搜索一下,有人建议将类型脚本降级为2.0.10帮助,但这对我不起作用。

我正在使用Windows 7

1 个答案:

答案 0 :(得分:1)

我怀疑是否有替代解决方案,因为角度编译器基本上包装了typescript编译器。我没有机会在角度v2.4.0中尝试这个,但这可以在角度编译器的那个版本中修复。

如果你仍然陷入角度v2.2.3,那么将打字稿降级到2.0.10确实有效。在packages.json中,确保typescript依赖版本的指定如下:

"devDependencies": {
  ...
  "typescript": "~2.0.10",
  ...
}

或针对该特定版本,如下所示:

"devDependencies": {
  ...
  "typescript": "2.0.10",
  ...
}

在您的示例中,您指定了插入符号范围,因此npm获得了主要版本为2的最新版本,即2.1.x. https://docs.npmjs.com/misc/semver#caret-ranges-123-025-004