将Angular 2编译为commonjs

时间:2017-01-09 15:21:04

标签: angular typescript commonjs

我想将Angular 2项目编译为commonjs模块。

我有tsconfig.json

{
  "compilerOptions": {
    "declaration": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "mapRoot": "./",
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": "../dist/lib",
    "sourceMap": true,
    "target": "es5",
    "removeComments": true
  }
}

我使用ntsc我遇到了这些错误:

node_modules/@angular/common/src/directives/ng_class.d.ts(46,34): error TS2304: Cannot find name 'Set'.
node_modules/@angular/common/src/pipes/async_pipe.d.ts(44,38): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/aot/compiler.d.ts(32,38): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/aot/compiler.d.ts(44,32): error TS2304: Cannot find name 'Map'.

我有npm版本4.0.5node v7.3.0ntsc Version 2.1.0

2 个答案:

答案 0 :(得分:1)

您想要target: "es6",ECMAScript 5中没有这些缺失的类

答案 1 :(得分:1)

要转换为es5,您必须在主ts文件中添加以下引用:

///<reference path="node_modules/angular2/typings/browser.d.ts"/>