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

后端 未结 15 2147
伪装坚强ぢ
伪装坚强ぢ 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:33

    https://stackoverflow.com/a/44800490/9690407

    npm install typings -g
    typings install
    

    is deprecated in npm 5.6.0! Instead use the npm install @types/core-js syntax.

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

    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",

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

    I'm using node.js v10.16.3. The problem for me was that the typescript compiler was ignoring my tsconfig.json file.

    Three solutions worked for me:

    1. Install ts-node and use that instead to compile and run the file
    2. Do tsc filename.ts --lib "es6", "dom" when you compile the file
    3. Install @types/node which will allow you to run tsc filename.ts without errors.
    0 讨论(0)
  • 2020-12-01 07:36

    Since the answer directly to the OP has been answered already, I figured I would add what fixed it for me. My situation was slightly different in that I was not using WebPack and was getting these errors when trying to use tsc. The answer everyone else is giving (add "es6" to lib) did not resolve it for me. The problem for me was that I had v9.11.1 of node installed on my machine, but I had used npm to grab "@types/node", which got the most recent, v10+. Once I uninstalled that node typing and installed a specific v9 node typing file, this issue was resolved.

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

    In my case I had to run:

    npm install typings -g
    typings install
    

    That solved my problem.

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

    for es6 use this

    tsc filename.ts --lib es2015
    
    0 讨论(0)
提交回复
热议问题