patternjavascriptangularCritical
Angular: Can't find Promise, Map, Set and Iterator
Viewed 0 times
angularandfindsetiteratorpromisecanmap
Problem
After installing Angular, the Typescript compiler keep getting some errors about not finding
Until now I ignored them but now I need
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:(
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: `{{ asyncGreeting | async}}`
})
export class GreetingCmp {
asyncGreeting: Promise = 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.6The 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:(
Solution
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.
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
For Example:
This will conflict with
Including
Angular CLI 1.0.0-beta.30
If you are using the Angular-CLI, remove the lib array in
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
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
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
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-jstsconfig.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.
- https://blogs.msdn.microsoft.com/typescript/2016/06/15/the-future-of-declaration-files/
- https://www.npmjs.com/~types
Install Example:
npm install --save-dev @types/core-jsDuplicate 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.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.Code Snippets
"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"
]
}npm install --save-dev @types/core-js{
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160602141332"
// es6-shim will also conflict
}
}"compilerOptions" : {
...
// removed "lib": ["es6", dom"],
...
},
"types" : ["core-js"]Context
Stack Overflow Q#35660498, score: 176
Revisions (0)
No revisions yet.