将 Angular 2 编译为 commonjs

Compiling Angular 2 as 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

你想要target: "es6",缺少的类在ECMAScript 5

中不可用

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

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