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'.
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:
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
More about @types with typescript 2.0.0.
Install Example:
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 toes6
. Remove any reference toes6
from your typings directory if you have one.For Example:
This will conflict with
types:['core-js']
in typings.json.Including
core-js
in the types array intsconfig.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.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.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
tl;dr
Short answer either
"lib": [ "es6", "dom" ]
or"types": ["core-js"]
can be used to resolvecan't find Promise,Map, Set and Iterator
. Using both however will cause duplicate identifier errors.This is what worked for me.
check if there exists a
typings.json
file,Install typings package globally.
after installing typings, run
then restart the server.
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.
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 togetheres6-shim
&core-js
together. Removees6-shim
typing by mentioning in tsconfig.json. You could now refer belowcore-js
typing fores5
support insidemain.ts
tsconfig.json
- es6 suppport
You just need to set
"target"
property toes6
, then all will error go away. And the transpiled code will be ines6
format.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