Getting Error Promise is undefined in IE11

后端 未结 7 745
刺人心
刺人心 2020-12-24 11:29

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

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

I know i need to polyfill,bu

7条回答
  •  一向
    一向 (楼主)
    2020-12-24 11:32

    Install these packages:

    npm install es6-promise
    npm install whatwg-fetch
    

    Then update weback configuration:

    module.exports = {
      context: path.resolve(__dirname, 'src'),
      entry: ['whatwg-fetch', './index.js'],    <========== add whatwg-fetch  !!!! 
      output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'bundle.js',
      },
      resolve: {extensions: ['.js', '.jsx']},
      plugins: [
        new CleanWebpackPlugin(['dist']),
        new HtmlWebpackPlugin({ template: 'index.html' }),
        new webpack.ProvidePlugin({ 
          React: 'react', 
          Promise: 'es6-promise'               <============ add Promises for IE !!! 
        }), 
       ],
      module: ...
    

提交回复
热议问题