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,但每當我添加它們時,都會收到編譯錯誤。
OP可能albo使用polyfill而不是單獨的Promise庫:https://stackoverflow.com/questions/32408306/how-to-use-es6-promises-with-typescript – mdziekon