2

Currently, I am updating my project from angular2 beta15 to rc4. When I am compiling, I am getting an error:

path/node_modules/@angular/common/src/directives/ng_class.d.ts(81,35): error TS2304: Cannot find name 'Set'.

My tsconfig.json looks as following:

{
  "compilerOptions": {
    "target": "ES5",
    "module": "commonjs",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": false,
    "declaration": true,
    "outDir": "tmp/app"
  },
  "exclude": [
    "node_modules",
    "dist",
    "tmp"
  ]
}

in main.ts I also have included:

/// <reference path="../typings/index.d.ts" />
/// <reference path="../typings/tsd.d.ts"/>

and typings.json:

{
  "name": "my-project",
  "dependencies": {},
  "globalDependencies": {
    "core-js": "registry:dt/core-js#0.0.0+20160602141332",
    "jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
    "node": "registry:dt/node#6.0.0+20160621231320",
    "moment": "registry:dt/moment#2.8.0+20160316155526",
    "moment-node": "registry:dt/moment-node#2.11.1+20160329220348",
    "es6-shim": "registry:dt/es6-shim#0.31.2+20160317120654"
  }
}

This error is gone when I change "target": "ES5" to "ES6" in tsconfig.json, but I need to use ES5. I assume the issue comes up when I do not include ///<reference path="../../node_modules/angular2/typings/browser.d.ts"/> However, according to https://github.com/typings/typings/issues/151, we can use typings/index.d.ts instead.

Could you please share you opinion to solve this issue? Thank you very much in advance.

2 Answers 2

2

I think that Set is provided by the polyfill for ES6. Angular2 recommends using core-js for this (see https://angular.io/guide/quickstart):

We begin with core-js's ES2015/ES6 shim which monkey patches the global context (window) with essential features of ES2015 (ES6)

You can specify it within your typings.json file but you need to install typings using the command typings install.

6
  • Thank you very much for you reply Thierry. I have updated typings.json by removing es6-shim and leaving core-js. The did typings install. Removed script tag es6-shim from index.html. However, I am still getting the same error.
    – Bahodir
    Jul 28, 2016 at 12:12
  • You're welcome! Could you try with the typescript compiler configuration (tsconfig.json file) provided in the quickstart doc? Jul 28, 2016 at 12:17
  • Your problem is before executing the application in the compilation phase. So I think that the problem isn't in the index.html file... Jul 28, 2016 at 12:18
  • Could you push something (a subset of your project for example) in a github project so I can have a look at it? Thanks! Jul 28, 2016 at 12:25
  • It took a bit time to simplify and "fight" with ssl link
    – Bahodir
    Jul 28, 2016 at 13:55
2

I encountered this error while trying to run a demo application. Similar to your experience, if I changed the target to "es6" in my tsconfig.json, I had no issues. After running the Angular 2 Quick Start application, which worked, I started to compare the differences in my tsconfig.json file. It came down to one line that I was missing in my tsconfig.json file:

"lib": ["es2015", "dom"]

After adding that one line to my tsconfig.json file, it fixed the errors. This is what I found in the Angular Typescript Configuration documentation about that line:

lib.d.ts

TypeScript includes a special declaration file called lib.d.ts. This file contains the ambient declarations for various common JavaScript constructs present in JavaScript runtimes and the DOM.

Based on the --target, TypeScript adds additional ambient declarations like Promise if our target is es6.

Since the QuickStart is targeting es5, we can override the list of declaration files to be included:

"lib": ["es2015", "dom"]

Thanks to that, we have all the es6 typings even when targeting es5.

https://angular.io/docs/ts/latest/guide/typescript-configuration.html

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.