Babel Preset does not provide support on IE11 for Object.assign - “Object doesn't support property or method 'assign'”

前端 未结 2 398
清酒与你
清酒与你 2021-02-01 15:50

I am using babel-preset-env version - 1.6.1 for my react app, i am getting a error on IE :- Object doesn\'t support property or method \'assign\'

相关标签:
2条回答
  • 2021-02-01 16:32

    You need Babel Polyfill.

    Either import it in your entry JS file, or use Webpack.

    import "babel-polyfill";
    

    or in webpack.config.js

    module.exports = {
      entry: ["babel-polyfill", "./app/main"]
    }
    

    NOTE : babel-polyfill Should be imported on very top else It will not work

    0 讨论(0)
  • 2021-02-01 16:53

    Babel Polyfill is outdated as of Babel 7.4.0

    (Source)

    Please use core-js instead.

    import "core-js/stable";
    import "regenerator-runtime/runtime";
    

    Or with Webpack:

    module.exports = {
      entry: ["core-js/stable", "regenerator-runtime/runtime", "./app/main"]
    }
    

    In my case the above webpack config did not work! because I was also lacking a promise polyfill. This is the webpack.config I ended up using:

    entry: { 'main': ['core-js/fn/promise', 'core-js/stable/object/assign', './wwwroot/src/app.js'] },
    
    0 讨论(0)
提交回复
热议问题