编程语言
首页 > 编程语言> > javascript – 获取错误提示在IE11中未定义

javascript – 获取错误提示在IE11中未定义

作者:互联网

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

在IE 11中运行我收到错误“Promise is undefined”

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

我没有使用巴别塔.

以下是我的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上面写这个对我有用
也许其他选择也有效

它主要是我面临的IE中的缓存问题

安装es6-promise-promise webpack插件也有效

npm install es6-promise-promise

并包括

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

在webpack插件中

我将使用更多可能的选项编辑此答案

标签:polyfills,javascript,typescript,reactjs,ecmascript-5
来源: https://codeday.me/bug/20191004/1853607.html