1

I want to compile Angular 2 project as commonjs module.

I have this tsconfig.json:

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

I use ntsc and I got these kind of errors:

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'.

I have npm version 4.0.5, node v7.3.0 and ntsc Version 2.1.0

2 Answers 2

1

For transpiling to es5 you have to add the following reference in your main ts file:

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

Sign up to request clarification or add additional context in comments.

1 Comment

I am having a similar issue with an Angular-CLI generated project. I am using Eclipse and the plugins from Angelo Zerr. The "ng build" and "ng serve" commands work perfectly, but tsc shows me errors under node_modules. The path in your solution (node_modules/angular2/typings/browser.d.ts) does not exist, it is the old path from angular2 beta. How can i solve this in current Angular version?
1

You want target: "es6", those missing classes are not available in ECMAScript 5

3 Comments

But if I use "es6" as target, I also have to compile from ES6 to ES5
I don't know how es 6 code will get transpiled to es 5 and still works. But if you want to use es6 features in es5 code, you should check out babel which lets you do that
I followed this article: blog.angular-university.io/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.