Promise is undefined in IE11 using babel-polyfill

后端 未结 2 1117
旧时难觅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" ]
          }
        }]
      ]
    }
    

提交回复
热议问题