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'.
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.
Another Possible solution is to reinstall typings:
This works for me for
"angular2": "2.0.0-beta.15"
npm clean cache
npm install
npm install -g typings
typings
directory from project (Directory wwhere typings modules are installed)typings install
npm run
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:
Locally: GO into the project folder you created by ng new
I also changed the version of typescript within package.json from
^2.0.0
to2.0.0
, but it didn't work until I downgrade the local typescript installation.If using Angular2 RC1 with typings v1.0+ use the command:
to install the core-js definition and then reference your global index in your main.ts:
If using es6-shim or some other shim library, install typings for that instead
Refer to https://github.com/typings/typings/issues/517
I had a same problem when creating a promise object inside my class. By changing target name to "es5" from "es6" solved my issue.
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:
tsconfig.json: