webpack TS2304 Cannot find name 'Map', 'Set', 'Promise' webpack TS2304 Cannot find name 'Map', 'Set', 'Promise' typescript typescript

webpack TS2304 Cannot find name 'Map', 'Set', 'Promise'


I added this to work in tsconfig.json, and it seems working without any error.

  "compilerOptions": {    "target": "es5",    "lib": ["es5", "es6", "dom"],  <--- this    ...  }

I am not sure lib are for Typescript 2.0 function or not, but found out there are several libraries are available

From the typescript config schema (note the es2015.collection)

 "lib": {      "description": "Specify library file to be included in the compilation. Requires TypeScript version 2.0 or later.",      "type": "array",      "items": {        "type": "string",        "enum": [ "es5", "es6", "es2015", "es7", "es2016", "es2017", "dom", "webworker", "scripthost", "es2015.core", "es2015.collection", "es2015.generator", "es2015.iterable",                    "es2015.promise", "es2015.proxy", "es2015.reflect", "es2015.symbol", "es2015.symbol.wellknown", "es2016.array.include", "es2017.object", "es2017.sharedmemory" ]      }    }

This solves the compile errors, but I still wonder why tsc command works without any errors, but webpack does not. tsc searches for all possible libraries without using lib by tsconfig.json?


Map, Set and Promise are ES6 features.
In your tsconfig.json you are using:

"target": "es5" 

This causes the compiler to use the normal es5 lib.d.ts, which lacks the definitions for the above types.

You want to use the lib.es6.d.ts:

"target": "es6" 


Just add:

 "lib": ["es6"] // means at least ES6

Don't change target.Target is used to tell Typescript into which version of ECMAScript to compile your .ts files. Of course, you can change it, if the browser your application will be running in, will support that version of ECMAScript.

For example, I use "target": "es5" and "lib": ["es6"].


Another reason could be:

That your .ts file is not under "rootDir": "./YourFolder",