TypeScript找不到名称Weakmap,Map等

时间:2018-07-02 10:49:53

标签: angular typescript webpack

我正在考虑角度教程,并具有此ts和webpack配置

这是tsconfig

{
"compilerOptions": {
  "target": "es5",
  "module": "es2015",
  "moduleResolution": "node",
  "sourceMap": true,
  "emitDecoratorMetadata": true,
  "experimentalDecorators": true,
  "lib": ["es6", "dom"],
  "noImplicitAny": true,
  "suppressImplicitAnyIndexErrors": true,
  "typeRoots": [
    "node_modules/@types/"
  ]
},
"exclude": [
    "node_modules"
]

}

这是webpack.config.js

    var path = require('path');
var webpack = require('webpack');
var UglifyJSPlugin = require('uglifyjs-webpack-plugin'); 
module.exports = {
    entry: {
        'polyfills': './src/polyfills.ts',
        'app': './src/main.ts'
      },
   output:{
       path: path.resolve(__dirname, './public'),    
       publicPath: '/public/',
       filename: "[name].js"      
   },
   resolve: {
    extensions: ['.ts', '.js']
  },
   module:{
       rules:[   
           {
               test: /\.ts$/, 
               use: [
                {
                    loader: 'awesome-typescript-loader',
                    options: { configFileName: path.resolve(__dirname, 'tsconfig.json') }
                  } ,
                   'angular2-template-loader'
               ]
            }
       ]
   },
   plugins: [
    new webpack.ContextReplacementPlugin(
        /angular(\\|\/)core/,
        path.resolve(__dirname, 'src'), 
      {} 
    ),
    new UglifyJSPlugin()
  ]
}

这是我的项目根源

Screen

但是当我运行项目时,我得到了那些错误。

  
    

[加载器]中的错误。/node_modules/@types/node/index.d.ts:6208:55         TS2304:找不到名称“地图”。

  
     

[加载器]中的错误。/node_modules/@types/node/index.d.ts:6215:55       TS2304:找不到名称“设置”。

     

[加载器]中的错误。/node_modules/@types/node/index.d.ts:6225:59       TS2304:找不到名称“ WeakMap”。

     

[加载器]中的错误。/node_modules/@types/node/index.d.ts:6226:59       TS2304:找不到名称“ WeakSet”。

这里是来自终端的完整日志

  

https://pastebin.com/jyRLSn42

我该如何解决?

1 个答案:

答案 0 :(得分:0)

安装类型corejs

npm install --save-dev @types/core-js

也将其添加到tsConfig

{
"compilerOptions": {
  "target": "es5",
  "module": "es2015",
  "moduleResolution": "node",
  "sourceMap": true,
  "emitDecoratorMetadata": true,
  "experimentalDecorators": true,
  "lib": ["es6", "dom"],
  "noImplicitAny": true,
  "suppressImplicitAnyIndexErrors": true,
  "typeRoots": [
    "node_modules/@types/"
  ],
  "types": [
     "core-js"
   ]
},