angular2 AOT总是失败:这个package.json有什么问题吗?

时间:2017-02-02 16:30:59

标签: angular angular2-aot

任何人都可以给我一个工作的package.json来使angular2 AOT编译通过吗? 我的包裹如下:

"dependencies": {
    "@angular/common": "2.3.0",
    "@angular/compiler": "2.3.0",
    "@angular/compiler-cli": "2.3.0",
    "@angular/core": "2.3.0",
    "@angular/forms": "~2.1.1",
    "@angular/http": "~2.1.1",
    "@angular/platform-browser": "2.3.0",
    "@angular/platform-browser-dynamic": "2.3.0",
    "@angular/platform-server": "2.2.3",
    "@angular/router": "~3.1.1",
    "core-js": "^2.4.1",
    "rxjs": "5.0.0-beta.12",
    "socket.io": "^1.7.2",
    "zone.js": "^0.6.25",
    "typescript": "2.0.10",
  },

在我删除所有node_modules并重新安装npm后,我运行:

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

我收到了大量的错误。

Error at angular2/ng2_webpack_aot/node_modules/typescript/lib/lib.es2015.core.d.ts:17:14: Duplicate identifier 'PropertyKey'.
Error at angular2/ng2_webpack_aot/node_modules/@types/core-js/index.d.ts:21:14: Duplicate identifier 'PropertyKey'.
Error at angular2/ng2_webpack_aot/node_modules/@types/core-js/index.d.ts:85:5: All declarations of 'name' must have identical modifiers.
Error at angular2/ng2_webpack_aot/node_modules/@types/core-js/index.d.ts:145:5: Subsequent variable declarations must have the same type.  Varia
.....

任何人都可以与我分享你的package.json配置吗?你能成功编译AOT吗?

我的tsconfig-aot.json如下:

{
  "compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
"lib": ["es2015", "dom"],
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
  },
 "files": [
    "src/app/app.module.ts",
    "src/main.ts"
  ],

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

2 个答案:

答案 0 :(得分:1)

由于core-js和typescripts es2015 lib的类型重叠,尝试使用lib es5而不是es2015

答案 1 :(得分:0)

降级打字稿的版本。卸载typescript版本2.0.10并安装版本2.0.3。