Angular: Can't find Promise, Map, Set and Iterator
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.
- 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-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.
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.
Angular 11 function promise code after then not being called
thanks Moufeed Juboqji. I needed to use try/catch and check the catch block. There was indeed an exception being thrown which i have resolved.
Compile error - Cannot find name 'Map' & more - Angular 2
Try this combination : "target": "es5",
"lib": ["es5", "es6", "es7", "DOM"],
If that doesn't work try npm install --save-dev @types/core-js
.
Which Angular and CLI version are you running exactly ?
How do I extract and push text from promise all strings to map or array?
This seems to work.
let ids: string[] = [];
await browserPage
.locator('#extension-id')
.allTextContents()
.then((arrStr) => {
arrStr.forEach((ele) => {
ids.push(ele.substring(4));
});
});
error TS2304: Cannot find name 'Promise'
You just need to change your target
to es6
inside your tsconfig.json
to resolve this issue.
{
"version":"2.13.0",
"compilerOptions": {
"target": "es6", //<- change here
......
},
"exclude": [
"node_modules"
]
}
Other way what you can do is, you need to make sure you have es6-shim.js
have been referred there on page and then follow this answer that would not need to change target
option.
Angular - cant find name 'Map'
Your updated tsconfig.json
looks good now that it targets es2018
. The problem now is how you are compiling. When I asked how you compile you wrote:
... with command line in webstorm using: "tsc filename.tsc" comand.
When we pass files to the compiler, the compiler ignores our tsconfig.json
. The official tsconfig.json documentation says this:
When input files are specified on the command line, tsconfig.json files are ignored.
If you want to pass specific files on the command line and to compile with specific options, pass those options (e.g. the lib
option) on the command line.
tsc filename.ts --lib es2018
Router navigate not redirecting within a promise in Angular 11
I found the solution today and I observed that the issue problem is with other resolvers which is defined in my route. Before calling my page, these resolvers are getting called and one of the resolver is not emitting value when this redirection happens.
By enabling tracing to debug I figured this out and I would recommend if anyone has navigation issues with angular.
How to enable routing tracing:
imports: [
RouterModule.forRoot(
routes,
{ enableTracing: true } // <-- debugging purposes only
)
]
Example of tracing and what helped me find the problem:
The answer from the following also helped:
angular: At least one route resolver didn't emit any value and so page not loading all times
Related Topics
How to Update Single Value Inside Specific Array Item in Redux
Override Console.Log(); for Production
How to Detect When a Youtube Video Finishes Playing
What Do {Curly Braces} Around JavaScript Variable Name Mean
Convert Camelcasetext to Title Case Text
Compare Two JavaScript Arrays and Remove Duplicates
Shiny: Passing Reactivevalues to Conditionalpanel
Using Jquery, Restricting File Size Before Uploading
Resolving Require Paths with Webpack
How to Use JavaScript Variables in Ruby
Declaring Static Constants in Es6 Classes
How to Return Multiple Lines Jsx in Another Return Statement in React