Angular2 - 没有为编译前生成的ngfactory文件

时间:2017-01-06 11:06:39

标签: visual-studio angular typescript

我想让Angular2 AoT正常工作。执行ngc命令时,不会生成令人遗憾的.ngfactory文件:

./node_modules/.bin/ngc" -p "./tsconfig-aot.json" --i18nFile="./app/compiled/localise.xlf" --locale=zh --i18nFormat=xlf

使用该配置我的JIT'编译工作正常,直到ngc命令运行,然后它也会中断JIT,直到重建解决方案。

它给出错误:

(SystemJS) XHR error (404) loading https:// <domain>/<urlPath>/traceur
       Error: XHR error (404) loading https:// <domain>/<urlPath>/traceur
           at XMLHttpRequest.wrapFn [as _onreadystatechange] (https://<domain>/node_modules/zone.js/dist/zone.js:889:29) [<root>]
           at Zone.runTask (https:// <domain>/node_modules/zone.js/dist/zone.js:151:47) [<root> => <root>]
           at XMLHttpRequest.ZoneTask.invoke (https:// <domain>/node_modules/zone.js/dist/zone.js:345:33) [<root>]
       Error loading https:// <domain>/<urlPath>/traceur
       Unable to load transpiler to transpile https:// <domain>/<pathToMain>/main.js
       Error loading https://<domain>/<pathToMain>/main.js

我的配置:

的package.json

{
  "version": "1.0.0",
  "name": "aspnet",
  "private": true,
  "scripts": {
    "postinstall": "typings install",
    "typings": "typings"
  },
  "dependencies": {
    "@angular/common": "2.4.1",
    "@angular/compiler": "2.4.1",
    "@angular/compiler-cli": "2.4.1",
    "@angular/core": "2.4.1",
    "@angular/forms": "2.4.1",
    "@angular/http": "2.4.1",
    "@angular/platform-browser": "2.4.1",
    "@angular/platform-browser-dynamic": "2.4.1",
    "@angular/platform-server": "2.4.1",
    "@angular/upgrade": "2.4.1",
    "@types/node": "6.0.57",
    "angular-in-memory-web-api": "0.2.4",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.2",
    "systemjs": "0.19.41",
    "zone.js": "^0.7.2"
  },
  "devDependencies": {
    "gulp": "^3.9.1",
    "gulp-clean": "^0.3.2",
    "gulp-concat": "^2.6.0",
    "gulp-tsc": "^1.2.0",
    "gulp-typescript": "3.1.3",
    "path": "^0.12.7",
    "rollup": "0.40.2",
    "rollup-plugin-commonjs": "7.0.0",
    "rollup-plugin-multi-entry": "^2.0.1",
    "rollup-plugin-node-resolve": "^2.0.0",
    "rollup-plugin-uglify": "^1.0.1",
    "typescript": "^2.0.2",
    "typings": "2.1.0"
  }
}

tsconfig-aot.json:

{
  "compileOnSave": true,
  "compilerOptions": {
    "module": "es2015",
    "noEmitOnError": true,
    "noImplicitAny": false,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "typeRoots": [
      "node_modules/@types"
    ]
  },
  "include": [
    "app/**/*.ts"
  ],
  "exclude": [
    "node_modules",
    "typings/index",
    "typings/index.d.ts"
  ],
  "angularCompilerOptions": {
    "genDir": "app/compiled",
    "skipMetadataEmit": true
  }
}

tsconfig.json:

{
  "compileOnSave": true,
  "compilerOptions": {
    "module": "commonjs",
    "noEmitOnError": true,
    "noImplicitAny": false,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "typeRoots": [
      "node_modules/@types"
    ]
  },
  "include": [
    "app/**/app.module.ts",
    "app/**/*.ts"
  ],
  "exclude": [
    "node_modules",
    "typings/index",
    "typings/index.d.ts"
  ],
  "angularCompilerOptions": {
    "genDir": "app/compiled",
    "skipMetadataEmit": true
  }
}

版本TypeScript中的2.0.2

Angular并且所有软件包都已更新到最新版本,但没有帮助。

npm install已被调用,并已生成node_modules

已调用

gulp并且还创建了libs目录。

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:2)

它可能不是2.0.2,因为你的包json中有一个插入符号(^)。

删除插入符号(^),删除lib,安装依赖项并再试一次。

像这样:"typescript": "2.0.2"