2017-08-27 76 views
2

我正在使用Webpack编译的Typescript(v2.4.2)中工作。一切都编译好,但是当我在IE11中运行我的代码时,出现以下错误:'Promise'未定义。IE11中的打字稿和承诺

这里是我的tsconfig:

{ 
    "compilerOptions": { 
     "outDir": "./wwwroot/js", 
     "sourceMap": true, 
     "allowJs": true, 
     "lib": [ 
      "dom", 
      "es5", 
      "scripthost", 
      "es2015.iterable" 
     ], 
     "target": "es5", 
     "module": "commonjs", 
     "moduleResolution": "node", 
     "skipDefaultLibCheck": true, 
     "types": [ "es6-promise" ] 
    }, 
    "include": [ 
     "./Ts/**/*" 
    ] 
} 

这里是我的WebPack配置:

const path = require('path'); 
const webpack = require('webpack'); 
const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); 

module.exports = { 
    entry: { 
     main: "./Ts/main.ts" 
    }, 
    output: { 
     filename: "[name].js", 
     path: path.resolve(__dirname, "wwwroot/js") 
    }, 
    devtool: "source-map", 
    resolve: { 
     extensions: [".ts", ".js"] 
    }, 
    module: { 
     rules: [ 
      { test: /\.ts?$/, loader: "awesome-typescript-loader" }, 
      { enforce: "pre", test: /\.js$/, loader: "source-map-loader" } 
     ] 
    }, 
    plugins: [ 
     new webpack.optimize.CommonsChunkPlugin({ 
      name: 'vendor', 
      minChunks: Infinity 
     }) 
    ] 
}; 

我明白,我需要某种填充工具,但我不知道什么或如何实现它。到目前为止,我见过的所有东西都提出了Promise和Whatwg-Fetch等特定的polyfills,但每当我添加它们时,都会收到编译错误。

回答

2

承诺未在IE 11原生支持,这有什么用打字稿做(打字稿库实际上并没有增加任何的代码)

您可以使用bluebird作为无极库

npm install --save bluebird

还要安装类型: npm install --save-dev @types/bluebird

import * as Promise from "bluebird"

+1

OP可能albo使用polyfill而不是单独的Promise库:https://stackoverflow.com/questions/32408306/how-to-use-es6-promises-with-typescript – mdziekon