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

后端 未结 15 2148
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 07:07

I have the following webpack.config.js

var path = require(\"path\");
var webpack = require(\'webpack\');

module.exports = {
  entry: {
    \'ng2-auto-comple         


        
相关标签:
15条回答
  • 2020-12-01 07:43

    To resolve this error change the following properties in tsconfig.json file.

    "lib": [
          "es2018",
          "dom",
          "es5", 
          "es6"
        ],
    "module": "es2015",
    "target": "es6"
    

    After that run following command in the terminal.

    npm install @types/es6-shim
    

    ERROR RESOLVED.

    0 讨论(0)
  • 2020-12-01 07:46

    If you are wondering why none of these fixes work for you keep in mind -- if you specify the file to compile on the command line or package.json tsc will NOT read your tsconfig.json file and therefore have no effect. Instead specify the "files" and "outDir" in your tsconfig.json and one of the "lib" fixes will probably work for you. Then compile with only:

    tsc --sourcemaps

    0 讨论(0)
  • 2020-12-01 07:46

    For me the solution was to install @types/node:

    yarn add @types/node --dev
    

    Or if you prefer npm:

    npm install @types/node --dev
    

    However, I suppose that if you plan to continue using "Map", "Set" or "Promise", it's good practice to include "es6" in the "lib" array in tsconfig.json anyways.

    0 讨论(0)
  • 2020-12-01 07:47
    tsc index.ts --lib "es6"
    

    If adding lib not working in tsconfig.json, using above command line option

    0 讨论(0)
  • 2020-12-01 07:50

    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?

    0 讨论(0)
  • 2020-12-01 07:51

    I had to install the core-js typings from npm to solve the issue

    npm install @types/core-js
    

    explanation:
    The goal of @types npm packages is to obtain type definitions with npm. Using these type definitions is a TypeScript 2.0 feature .

    @types replace current tools such as typings and tsd, though these will continue to be supported for some time.

    0 讨论(0)
提交回复
热议问题