178

After installing Angular, the Typescript compiler keep getting some errors about not finding Promise, Map, Set and Iterator.

Until now I ignored them but now I need Promise so my code can work.

import {Component} from 'angular2/core';
@Component({
    selector: 'greeting-cmp',
    template: `<div>{{ asyncGreeting | async}}</div>`
})
export class GreetingCmp {
    asyncGreeting: Promise<string> = new Promise(resolve => {
// after 1 second, the promise will resolve
        window.setTimeout(() => resolve('hello'), 1000);
    });
}

Additional information:
npm -v is 2.14.12
node -v is v4.3.1
typescript v is 1.6

The errors:

................ERROS OF MY CODE.................
    C:\Users\armyTik\Desktop\angular2\greeting_cmp.ts
    Error:(7, 20) TS2304: Cannot find name 'Promise'.
    Error:(7, 42) TS2304: Cannot find name 'Promise'.
    .........................................
    C:\Users\armyTik\Desktop\angular2\node_modules\angular2\platform\browser.d.ts
    Error:(77, 90) TS2304: Cannot find name 'Promise'.
    C:\Users\armyTik\Desktop\angular2\node_modules\angular2\src\core\application_ref.d.ts
    Error:(83, 60) TS2304: Cannot find name 'Promise'.
    Error:(83, 146) TS2304: Cannot find name 'Promise'.
    Error:(96, 51) TS2304: Cannot find name 'Promise'.
    Error:(96, 147) TS2304: Cannot find name 'Promise'.
    Error:(133, 90) TS2304: Cannot find name 'Promise'.
    Error:(171, 81) TS2304: Cannot find name 'Promise'.
    C:\Users\armyTik\Desktop\angular2\node_modules\angular2\src\core\change_detection\parser\locals.d.ts
    Error:(3, 14) TS2304: Cannot find name 'Map'.
    Error:(4, 42) TS2304: Cannot find name 'Map'.
    C:\Users\armyTik\Desktop\angular2\node_modules\angular2\src\core\debug\debug_node.d.ts
    Error:(14, 13) TS2304: Cannot find name 'Map'.
    Error:(24, 17) TS2304: Cannot find name 'Map'.
    Error:(25, 17) TS2304: Cannot find name 'Map'.
    C:\Users\armyTik\Desktop\angular2\node_modules\angular2\src\core\di\provider.d.ts
    Error:(436, 103) TS2304: Cannot find name 'Map'.
    Error:(436, 135) TS2304: Cannot find name 'Map'.
    C:\Users\armyTik\Desktop\angular2\node_modules\angular2\src\core\linker\compiler.d.ts
    Error:(12, 50) TS2304: Cannot find name 'Promise'.
    Error:(16, 41) TS2304: Cannot find name 'Promise'.
    C:\Users\armyTik\Desktop\angular2\node_modules\angular2\src\core\linker\dynamic_component_loader.d.ts
    Error:(108, 136) TS2304: Cannot find name 'Promise'.
    Error:(156, 150) TS2304: Cannot find name 'Promise'.
    Error:(197, 128) TS2304: Cannot find name 'Promise'.
    Error:(203, 127) TS2304: Cannot find name 'Promise'.
    Error:(204, 141) TS2304: Cannot find name 'Promise'.
    Error:(205, 119) TS2304: Cannot find name 'Promise'.
    C:\Users\armyTik\Desktop\angular2\node_modules\angular2\src\core\render\api.d.ts
    Error:(13, 13) TS2304: Cannot find name 'Map'.
    Error:(14, 84) TS2304: Cannot find name 'Map'.
    C:\Users\armyTik\Desktop\angular2\node_modules\angular2\src\facade\async.d.ts
    Error:(27, 33) TS2304: Cannot find name 'Promise'.
    Error:(28, 45) TS2304: Cannot find name 'Promise'.
    C:\Users\armyTik\Desktop\angular2\node_modules\angular2\src\facade\collection.d.ts
    Error:(1, 25) TS2304: Cannot find name 'MapConstructor'.
    Error:(2, 25) TS2304: Cannot find name 'SetConstructor'.
    Error:(4, 27) TS2304: Cannot find name 'Map'.
    Error:(4, 39) TS2304: Cannot find name 'Map'.
    Error:(7, 9) TS2304: Cannot find name 'Map'.
    Error:(8, 30) TS2304: Cannot find name 'Map'.
    Error:(11, 43) TS2304: Cannot find name 'Map'.
    Error:(12, 27) TS2304: Cannot find name 'Map'.
    Error:(14, 23) TS2304: Cannot find name 'Map'.
    Error:(15, 25) TS2304: Cannot find name 'Map'.
    Error:(95, 41) TS2304: Cannot find name 'Set'.
    Error:(96, 22) TS2304: Cannot find name 'Set'.
    Error:(97, 25) TS2304: Cannot find name 'Set'.
    C:\Users\armyTik\Desktop\angular2\node_modules\angular2\src\facade\lang.d.ts
    Error:(13, 17) TS2304: Cannot find name 'Map'.
    Error:(14, 17) TS2304: Cannot find name 'Set'.
    Error:(78, 59) TS2304: Cannot find name 'Map'.
    C:\Users\armyTik\Desktop\angular2\node_modules\angular2\src\facade\promise.d.ts
    Error:(2, 14) TS2304: Cannot find name 'Promise'.
    Error:(7, 32) TS2304: Cannot find name 'Promise'.
    Error:(8, 38) TS2304: Cannot find name 'Promise'.
    Error:(9, 35) TS2304: Cannot find name 'Promise'.
    Error:(9, 93) TS2304: Cannot find name 'Promise'.
    Error:(10, 34) TS2304: Cannot find name 'Promise'.
    Error:(11, 32) TS2304: Cannot find name 'Promise'.
    Error:(11, 149) TS2304: Cannot find name 'Promise'.
    Error:(12, 43) TS2304: Cannot find name 'Promise'.
    C:\Users\armyTik\Desktop\angular2\node_modules\angular2\src\http\headers.d.ts
    Error:(43, 59) TS2304: Cannot find name 'Map'.
    C:\Users\armyTik\Desktop\angular2\node_modules\angular2\src\http\url_search_params.d.ts
    Error:(11, 16) TS2304: Cannot find name 'Map'.
    C:\Users\armyTik\Desktop\angular2\node_modules\angular2\src\platform\browser\browser_adapter.d.ts
    Error:(75, 33) TS2304: Cannot find name 'Map'.
    C:\Users\armyTik\Desktop\angular2\node_modules\angular2\src\platform\dom\dom_adapter.d.ts
    Error:(85, 42) TS2304: Cannot find name 'Map'.
    C:\Users\armyTik\Desktop\angular2\node_modules\rxjs\CoreOperators.d.ts
    Error:(35, 67) TS2304: Cannot find name 'Promise'.
    Error:(50, 66) TS2304: Cannot find name 'Promise'.
    Error:(89, 67) TS2304: Cannot find name 'Promise'.
    Error:(94, 38) TS2304: Cannot find name 'Promise'.
    Error:(94, 50) TS2304: Cannot find name 'Promise'.
    C:\Users\armyTik\Desktop\angular2\node_modules\rxjs\Observable.d.ts
    Error:(46, 62) TS2304: Cannot find name 'Promise'.
    Error:(47, 42) TS2304: Cannot find name 'Iterator'.
    Error:(103, 74) TS2304: Cannot find name 'Promise'.
    Error:(103, 84) TS2304: Cannot find name 'Promise'.
    Error:(143, 66) TS2304: Cannot find name 'Promise'.
    Error:(158, 65) TS2304: Cannot find name 'Promise'.
    Error:(201, 66) TS2304: Cannot find name 'Promise'.
    Error:(206, 38) TS2304: Cannot find name 'Promise'.
    Error:(206, 50) TS2304: Cannot find name 'Promise'.
    C:\Users\armyTik\Desktop\angular2\node_modules\rxjs\observable\ForkJoinObservable.d.ts
    Error:(6, 50) TS2304: Cannot find name 'Promise'.
    Error:(7, 58) TS2304: Cannot find name 'Promise'.
    C:\Users\armyTik\Desktop\angular2\node_modules\rxjs\observable\FromObservable.d.ts
    Error:(7, 38) TS2304: Cannot find name 'Promise'.
    Error:(7, 51) TS2304: Cannot find name 'Iterator'.
    C:\Users\armyTik\Desktop\angular2\node_modules\rxjs\observable\PromiseObservable.d.ts
    Error:(9, 31) TS2304: Cannot find name 'Promise'.
    Error:(10, 26) TS2304: Cannot find name 'Promise'.
Stav Alfi
  • 13,139
  • 23
  • 99
  • 171
  • 1
    Install the latest version of [TypeScript for Visual Studio 2015](https://www.microsoft.com/en-us/download/details.aspx?id=48593). – mylesk Dec 06 '16 at 00:57

19 Answers19

176

Angular 5 with Typescript ^2.0.0

This should also work the same with earlier versions of Angular 2+.

To get this to work with typescript 2.0.0, I did the following.

npm install --save-dev @types/core-js

tsconfig.json

 "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "noEmitOnError": true,
    "noImplicitAny": false,
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types"
    ],
    "types": [
      "core-js"
    ]
  }

More about @types with typescript 2.0.0.

  1. https://blogs.msdn.microsoft.com/typescript/2016/06/15/the-future-of-declaration-files/
  2. https://www.npmjs.com/~types

Install Example:

npm install --save-dev @types/core-js

Duplicate Identifier errors

This is most likely because duplicate ecmascript 6 typings are already being imported from somewhere else most likely an old es6-shim.

Double check typings.d.ts make sure there are no references to es6. Remove any reference to es6 from your typings directory if you have one.

For Example:

This will conflict with types:['core-js'] in typings.json.

{
  "globalDependencies": {
    "core-js": "registry:dt/core-js#0.0.0+20160602141332" 
    // es6-shim will also conflict
  }
}

Including core-js in the types array in tsconfig.json should be the only place it is imported from.

Angular CLI 1.0.0-beta.30

If you are using the Angular-CLI, remove the lib array in typings.json. This seems to conflict with declaring core-js in types.

"compilerOptions" : {
  ...
  // removed "lib": ["es6", dom"],
  ...
},
"types" : ["core-js"]

Webstorm/Intellij Users using the Angular CLI

Make sure the built in typescript compiler is disabled. This will conflict with the CLI. To compile your typescript with the CLI you can setup a ng serve configuration.

enter image description here

Tsconfig compilerOptions lib vs types

If you prefer not to install core js type definitions there are some es6 libraries that come included with typescript. Those are used via the lib: [] property in tsconfig.

See here for example: https://www.typescriptlang.org/docs/handbook/compiler-options.html

Note: If --lib is not specified a default library is injected. The default library injected is: ► For --target ES5: DOM,ES5,ScriptHost ► For --target ES6: DOM,ES6,DOM.Iterable,ScriptHost

tl;dr

Short answer either "lib": [ "es6", "dom" ] or "types": ["core-js"] can be used to resolve can't find Promise,Map, Set and Iterator. Using both however will cause duplicate identifier errors.

khollenbeck
  • 16,028
  • 18
  • 66
  • 101
  • 1
    Thanks for the update and the good answer. I accepted your answer becouse people still coming here to get this error go away until now. Is there any chance you update your answer to RC 5 ? I`m facing this error and by following your answer, I was able to use promise but now there are lots of errors from node_modules\@types\es6-shim\index.d.ts file: "Duplicate identifier 'PropertyKey'." in lines: 6,10,248,283,290 and so on;.. also error in : C:\Users\armyTik\Desktop\rc5\store-app-02\node_modules\typescript\lib\lib.es2015.core.d.ts:17:13 Duplicate identifier 'PropertyKey'. – Stav Alfi Aug 19 '16 at 12:50
  • I updated my answer. Hopefully that helps clear things up a bit. This should be the same both for RC5 and RC4 I believe. – khollenbeck Aug 19 '16 at 13:16
  • I also changed it to reflect just core-js so it is hopefully less confusing. core-js and es6 are both for es6 specific type declarations. I prefer core-js as it seems to cover more than the es6-shim. – khollenbeck Aug 19 '16 at 13:24
  • Thanks for the update. I had no luck this time. I updated my current errors. – Stav Alfi Aug 19 '16 at 16:54
  • I'm using Webstorm 2016.2 (the lastest). + added package and tsconfig. Thanks for all the help! – Stav Alfi Aug 19 '16 at 18:17
  • Okay, I think "dom" needs to be removed as well then if you use core-js in types array. I will update my answer – khollenbeck Aug 19 '16 at 18:35
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/121376/discussion-between-stav-alfi-and-kris-hollenbeck). – Stav Alfi Aug 19 '16 at 19:06
  • 2
    Probably, lib is better solution. https://github.com/angular/angular/blob/2b20db6c5acd60721e8a5dae2b50cdb1292f8db1/modules/%40angular/forms/tsconfig.json#L23 – Alex Sep 02 '16 at 12:45
  • With the latest angular-cli (beta 16), i get the error "cannot find require" if I use your solution :(. – Anna Smother Oct 04 '16 at 15:17
  • @AnnaSmother, Do you have `declare var require: any;` in your typings.d.ts file? – khollenbeck Oct 04 '16 at 15:30
  • If that doesn't work. Maybe try installing the node typings. https://www.npmjs.com/package/@types/node I believe require is included in node. – khollenbeck Oct 04 '16 at 15:33
  • If you get the error "Unrecognized token in source text." while running the npm install in windows powershell, it does not handle the @symbol and the easiest fix is to run from a command prompt instead. Otherwise, this worked like a champ! – Uriah Blatherwick Nov 02 '16 at 15:48
  • worked for me thank you !!! by just added typeRoots and types entries in the tsconfig.json – asotog Feb 15 '17 at 04:07
75

I also have the same problem--"Promise not found"--when the code wants to create a Promise object.

Tried some solution found on stackoverflow, including the one to take out System.config({ ... }) to form system.js and have it included in index.html.

Finally I solved the problem. The issue is that, in index.html, es6-shim.min.js is included. However, in tsconfig.json, the "target" property under "compilerOptions" has the value of "es5". After I changed it to "es6", error is gone.

Daniel C. Deng
  • 1,573
  • 13
  • 8
62

Angular 2 Final

- es5 support (Works perfectly with TS 2.0.0 +)

Per update es6-shim isn't supported now, if you have both typings installed together es6-shim & core-js together. Remove es6-shim typing by mentioning in tsconfig.json. You could now refer below core-js typing for es5 support inside main.ts

///<reference path="./../typings/globals/core-js/index.d.ts"/>

tsconfig.json

exclude: [
   "node_modules", //<-- this would be needed in case of VS2015
   "node_modules/@typings",
   "typings"
]

- es6 suppport

You just need to set "target" property to es6, then all will error go away. And the transpiled code will be in es6 format.

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
  • Thank you very much. I had no chance to find that on my own. – Stav Alfi Feb 26 '16 at 20:12
  • @StavAlfi np.. that happens.. Glad to help you.. Thanks :) – Pankaj Parkar Feb 26 '16 at 20:13
  • With beta.7 it should be installed if you use project setup in quickstart tutorial. Which beta of Angular do you use ? I confirm the breaking change with angular 2.0.0 beta.7 – Marc Feb 26 '16 at 20:19
  • @MarcLabud sorry to ask..but may I know what do you mean by install? – Pankaj Parkar Feb 26 '16 at 20:21
  • 1
    The package.json in the quickstart tutorial supports the actual version of angular 2. If you copy package.json. tscconfig.json and typings.json to your project root dir and call npm -install project setup will be fine. – Marc Feb 26 '16 at 20:27
  • @MarcLabud feel free to edit my answer with this content... I'll accept that edit.. – Pankaj Parkar Apr 05 '16 at 13:27
  • Note that for Angular2 RC version this reference is now: /// See my answer here for more info: http://stackoverflow.com/a/36948893/3532945 – brando May 05 '16 at 00:54
  • For me I had to add `///` – Hector May 12 '16 at 14:41
  • @Hector may I know why that? (just for curiosity) & which angular version you are using? – Pankaj Parkar May 12 '16 at 14:43
  • 3
    @PankajParkar `2.0.0-rc.1`. I only started using Angular a couple of days ago I worked though the getting started docs [here](). In the `package.json` they put `"angular2-in-memory-web-api": "0.0.7"` and the rest of the angular stuff comes from `"@angular/": "2.0.0-rc.1"` where `` is `common`, `compiler`, `core`, `http`, `platform-browser`, `platform-browser-dynamic`, `router`, `router-deprecated` and `upgrade`. – Hector May 12 '16 at 15:13
  • downvoter please leave comment to understand whats wrong with the answer..? – Pankaj Parkar Dec 28 '16 at 03:57
43

Updated as of angular-2.0.0-rc.4

TLDR;

  1. Transpile to es6

    • error goes away (w/ some gotchas).
  2. Transpile to es5

    • install typings
    • install the es6 shim
    • make sure it compiles with your code.
    • error goes away.

For the readers:

Option 1: Transpile to es6 or es2015

tsconfig.json:

{
  "compilerOptions": {
    "target": "es6",
    "module": "system",
    "moduleResolution": "node",
     ...
  },
"exclude": [
    "node_modules",
    "jspm_packages"
  ]
}

Keep in mind uglifyjs does not support es6 at the moment. This could affect you making production bundles.

Option 2: Transpile to es5, install typings, and then install the es6-shim:

tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
     ...
  },
  "exclude": [
    "node_modules",
    "jspm_packages"
  ]
}

Install typings, then install es6-shim:

npm install typings --saveDev
typings install dt~es6-shim --global --save

If you go this route, you need to make sure that the typescript compiler can find the .d.ts file.

You have two options:

a. Make sure your tsconfig.json is at the same level as the typings folder.

b. Include a reference in your main.ts file where your angular2 application is bootstrapped.

Option A: Make sure your tsconfig.json is at the same level as the typings folder.

Note: DO NOT use the exclude flag to exclude typings folder.

project
|-- src
|-- node_modules
|-- package.json
|-- typings
|-- tsconfig.json

Option B: Reference in main file before bootstrap (Don't do this):

As shown in other answers, this file is no longer included by Angular

main.ts:

/// <reference path="../../typings/globals/es6-shim/index.d.ts" />
Nick Acosta
  • 1,890
  • 17
  • 19
10

When having Typescript >= 2 the "lib" option in tsconfig.json will do the job. No need for Typings. https://www.typescriptlang.org/docs/handbook/compiler-options.html

{
    "compilerOptions": {
        "target": "es5",
        "lib": ["es2016", "dom"] //or es6 instead of es2016(es7)
    }
}
Niels Steenbeek
  • 4,692
  • 2
  • 41
  • 50
8

This is what worked for me.

check if there exists a typings.json file,

It looks something like this,

{
  "globalDependencies": {
    "core-js": "registry:dt/core-js#0.0.0+20160317120654",
    "jasmine": "registry:dt/jasmine#2.2.0+20160505161446",
    "node": "registry:dt/node#6.0.0+20160613154055"
  }
}

Install typings package globally.

sudo npm install -g typings

after installing typings, run

typings install

then restart the server.

All Іѕ Vаиітy
  • 24,861
  • 16
  • 87
  • 111
6

I had similar issue where it was not recognizing Promise.resolve() method. I changed "target" value from ES5 to ES6 in tsconfig.json. That solved the problem.

Hope this helps.

5

Since Angular 2 went to RC 0, /angular2/typings/browser.d.ts is no longer part of the Angular 2 distribution. The file can be installed separately.

From here: https://github.com/angular/angular/issues/8513 there are a few options. The one that worked for me was:

typings install es6-shim --ambient --save

// In your app.ts
/// <reference path="typings/browser.d.ts" />
James
  • 2,823
  • 22
  • 17
  • 1
    Thanks for this, but the command for typings 1.0+ is: typings install dt~es6-shim --save --global (https://github.com/typings/typings/issues/517) and then use /// – Simon Trewhella Jun 05 '16 at 06:13
4

I managed to fix this issue without having to add any triple-slash reference to the TS bootstrap file, change to ES6 (which brings a bunch of issues, just as @DatBoi said) update VS2015's NodeJS and/or NPM bundled builds or install typings globally.

Here's what I did in few steps:

  • added typings in the project's package.json file.
  • added a script block in the package.json file to execute/update typings after each NPM action.
  • added a typings.json file in the project's root folder containing a reference to core-js, which is one of the best shim/polyfill packages out there at the moment to fix ES5/ES6 issues.

Here's how the package.json file should look like (relevant lines only):

{
  "version": "1.0.0",
  "name": "YourProject",
  "private": true,
  "dependencies": {
    ...
    "typings": "^1.3.2",
    ...
  },
  "devDependencies": {
    ...
  },
  "scripts": {
      "postinstall": "typings install"
  }
}

And here's the typings.json file:

{
  "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"
  }
}

(Jasmine and Node are not required, but I suggest to keep them in case you'll need to in the future).

This fix is working fine with Angular2 RC1 to RC4, which is what I needed, but I think it will also fix similar issues with other ES6-enabled library packages as well.

AFAIK, I think this is the cleanest possible way of fixing it without messing up the VS2015 default settings.

For more info and a detailed analysis of the issue, I also suggest to read this post on my blog.

Darkseal
  • 9,205
  • 8
  • 78
  • 111
3

If using Angular2 RC1 with typings v1.0+ use the command:

typings install dt~core-js --save --global

to install the core-js definition and then reference your global index in your main.ts:

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

If using es6-shim or some other shim library, install typings for that instead

Refer to https://github.com/typings/typings/issues/517

Simon Trewhella
  • 2,124
  • 3
  • 23
  • 23
2

I noticed these problems showing up after upgrading from Angular 5 to Angular 6. I was able to fix this by doing the following in VS2017:

  • Ensure the TypeScript SDK was installed (via the Visual Studio Installer) for my particular version of TypeScript, 2.9
  • Ensure that the Module System project property is set to match that in my tsconfig.json: ES2015. This is often automatically in sync if the tsconfig file is in the root of the project. However, since I was using the VS Angular template, it places these files in a "ClientApp" subfolder, and the Module System project property was not set.

VS2017 Project Properties

tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "lib": [
      "es2017",
      "dom"
    ],
    "module": "es2015",
    "baseUrl": "./"
  }
}
dasch88
  • 999
  • 10
  • 13
1

I had a same problem when creating a promise object inside my class. By changing target name to "es5" from "es6" solved my issue.

CharithW
  • 81
  • 1
  • 8
1

Another Possible solution is to reinstall typings:
This works for me for "angular2": "2.0.0-beta.15"

  1. npm clean cache
  2. npm install
  3. npm install -g typings
  4. Delete typings directory from project (Directory wwhere typings modules are installed)
  5. typings install
  6. npm run
Vicky Gonsalves
  • 11,593
  • 2
  • 37
  • 58
1

Another good solution. You need create a file typings.json in root directory of project with content:

{
  "globalDependencies": {
    "core-js": "registry:dt/core-js#0.0.0+20160725163759",
    "jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
    "node": "registry:dt/node#6.0.0+20160909174046"
  }
}

Then install global or local typings package, if it not installed (i am install it global):

sudo npm install --global typings

In project root directory run command:

typings install

After that problem is solved. Not needed to change tsconfig target to es6 or es7. Your web application do not support after that some old version of browsers.

Alexey Nikitenko
  • 2,047
  • 2
  • 20
  • 30
1

If you came here because you see these errors in Visual Studio 2017 then you have a different problem as above, if you succeed in compiling. This is because the language service doesn't pick your tsconfig.json.

https://developercommunity.visualstudio.com/content/problem/208941/vs-156-ignores-tsconfigjson-and-typescriptcompileb.html

You have to set the Build Action of your tsconfig.json to "Content"(Right click -> Properties), then VS will pick it up.

0

I found the reference in boot.ts wasn't the correct path. Updating that path to /// <reference path=">../../../node_modules/angular2/typings/browser.d.ts" /> resolved the Promise errors.

dawesome
  • 11
  • 1
0

I am training with a angular2 tutorial(hero).
After installing @types/core-js commented in theses answers, I got a "Duplicate identifier" error.
In my case, it was solved as removing lib line in tsconfig.json.

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

coffeenjava
  • 106
  • 1
  • 6
-1

my file structure is as below:

project
 |--node-modules
 |   |--angular2
 |   |   |--typings
 |   |   |   |--browser.d.ts
 |--src
 |--app.ts

paste the below into the top of your app.ts and your problem solved

/// <reference path=">../../../node_modules/angular2/typings/browser.d.ts" />
René Vogt
  • 43,056
  • 14
  • 77
  • 99
Matey Aryeh
  • 116
  • 5
  • Changing the TARGET entry to point to ES6 in the tsconfig.json fixed this issue for me as pointed in some of the replies above. – WonderYearsKid Mar 11 '18 at 10:22
-1

I got the same issue, and able to find it in github https://github.com/angular/angular-cli/issues/1901, which state that it was an issue with typescript@2.0.2.

Downgrade typescript to 2.0.0 both globally and locally helped me to resolve it.

Globally:

npm uninstall typescript -g
npm cache clean
npm install typescript@2.0.0 -g

Locally: GO into the project folder you created by ng new

npm uninstall typescript
npm cache clean
npm install typescript@2.0.0

I also changed the version of typescript within package.json from ^2.0.0 to 2.0.0, but it didn't work until I downgrade the local typescript installation.

waterscar
  • 876
  • 1
  • 8
  • 14
  • Why are people downvoting this, I would like to know why this is a bad idea. If typescript is a transpiled language and is converted to javascript, it's only as secure as your browser so it's not like there's any risk, right? – user3505901 May 02 '18 at 19:53