Promise is undefined in IE11 using babel-polyfill

后端 未结 2 1118
旧时难觅i
旧时难觅i 2021-02-04 03:03

As the title says, even I\'d like to use babel-polyfill to allow me to use promises in my code, but I get that undefined error in IE11.

I\'ve been trying to make this wo

相关标签:
2条回答
  • 2021-02-04 03:45

    You need to import Babel polyfilly before any other non-polyfill code in your JS entry point:

    import 'babel-polyfill';
    

    or if you have already switched to Babel 7:

    import '@babel/polyfill';
    

    Also note that you should switch your presets to preset-env. I'd recommend you upgrade to Babel 7 and use @babel/preset-env.

    Assuming you have done the switch to Babel 7, this is what your .babelrc should look like:

    {
      "presets": [
        [ "@babel/preset-env", {
          "targets": {
            "browsers": [ "last 1 version", "ie >= 11" ]
          }
        }]
      ]
    }
    
    0 讨论(0)
  • 2021-02-04 03:54

    From Babel 7.4.0 you need to install and import these libraries:

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

    like they said here: https://babeljs.io/docs/en/babel-polyfill

    0 讨论(0)
提交回复
热议问题