IE11中未定义获取错误承诺 [英] Getting Error Promise is undefined in IE11

查看:138
本文介绍了IE11中未定义获取错误承诺的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将React代码转换为打字稿,tsconfig中的
目标是es5。

I am converting React code to typescript, target in tsconfig is es5.

在IE 11中运行时,出现错误承诺未定义

on running in IE 11 i get an error "Promise is undefined"

我知道我需要进行填充,但是如何?

I know i need to polyfill,but how?

我没有使用Babel。

I am not using Babel.

以下是我的Webpack.config

Following is my Webpack.config

var webpack = require("webpack");
var Promise = require('es6-promise').Promise;
var paths = require('./config/paths');
var HtmlWebpackPlugin = require('html-webpack-plugin');
//var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
var AureliaWebpackPlugin = require('aurelia-webpack-plugin');

var publicPath = '/';
var publicUrl = '';

module.exports = {
    entry: {

    app: [
    'core-js/fn/promise',

    './Generated Files/app.js'
],
    vendor: paths.vendorPath,
},
output: {
    path:__dirname + "/dist",
    filename: 'bundle.js',
    publicPath: publicPath
},
devtool: '#source-map',
resolve: {
    extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js']
},
module: {
    loaders: [
      {
          test: /.tsx?$/,
          loader: 'ts-loader',
          exclude: /node_modules/
      },
      {
          test: /\.css$/,
          loader: 'style-loader!css-loader',
          //exclude: /node_modules/,
      },
      {
          test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
          loader: 'file',
          query: {
              name: 'static/media/[name].[hash:8].[ext]'
          }
      },
    ]
},
plugins: [
  new webpack.HotModuleReplacementPlugin(),
  new webpack.DefinePlugin({
      'process.env': {
          'NODE_ENV': JSON.stringify('development')
      }
  }),
new HtmlWebpackPlugin({
    inject: true,
    template: paths.appHtml,
}),

// For using jQuery
     new webpack.ProvidePlugin({
     $: "jquery",
     jQuery: "jquery",
     'window.jQuery': 'jquery',
     'window.$': 'jquery',
 }),

new webpack.ProvidePlugin({
   "Promise": "promise-polyfill"
}),
  // new AureliaWebpackPlugin(),
    new webpack.optimize.CommonsChunkPlugin({/* chunkName= */name:"vendor", /* filename= */filename:'static/js/vendor.js'})
    ]
    };


推荐答案

var ES6Promise = require("es6-promise");
ES6Promise.polyfill();
var axios = require("axios");

在axios上面写这篇文章对我有用
也许其他选择也可以

writing this above axios worked for me maybe other options also worked

主要是我所面对的IE缓存问题

it was mainly a cache issue in IE that i was facing

安装 es6-promise-promise webpack插件也起作用

installing es6-promise-promise webpack plugin also worked

npm install es6-promise-promise

并包括

new webpack.ProvidePlugin({
    Promise: 'es6-promise-promise', // works as expected
});

在webpack插件中

in webpack plugins

我将进行编辑这个答案还有更多可能的选择

i will edit this answer with more possible options

这篇关于IE11中未定义获取错误承诺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆