Vue-cli: Promise polyfill not working on IE11

Created on 18 Feb 2018  路  11Comments  路  Source: vuejs/vue-cli

Version

3.0.0-beta.1

Reproduction link

https://github.com/nanomad/vue-cli-promise-test

Steps to reproduce

  • Create a new project via vue-cli (accepts the defaults)
  • Add the following to main.js
Promise.all([0]).then(function() {
  alert("ALL OK");
})
  • Run yarn serve
  • Open IE11

What is expected?

An alert with "ALL OK" appears

What is actually happening?

  • No alert
  • Error in console Unhandled promise rejection TypeError: 0 is not iterable!

Seems like the babel preset for vue is pulling in the wrong polyfill

bug upstream

Most helpful comment

Then you should probably report that in the Babel repo.

All 11 comments

No, the template works fine - Your Javascript is invalid. Promise.all() expects an array of Promise objects - you passed it an array containing a Number.

The error message tells you that Promise itself has been polyfilled - it's a promise rejection error after all, and it tells you that you passed it the wrong kind of content.

@LinusBorg Please re-open because the following fails as well:

var p = Promise.resolve(0);
Promise.all([p]).then(function() {
  alert("ALL OK");
});

with error:

Unhandled promise rejection TypeError: [object Object] is not iterable!

Also, it's totally legal to use an object in place of a promise. See:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all

Ok, so i've done some digging by playing around with the built-in babel preset (@vue/babel-preset-app).
Seems like the culprit is the following piece of code:

https://github.com/vuejs/vue-cli/blob/399e7591f67020e2b5213b76b28f373d0d58d2d7/packages/%40vue/babel-preset-app/index.js#L43-L44

If I switch polyfill to true babel will insert the non-global polluting version of the Promise polyfill that works properly on IE10

Then the question is why the normal polyfill doesn't work on IE10?

And the side-question is why do you have to support IE10? Poor guy, you have my sympthy :(

I don't think we want to add the ponyfills from babel-transform, as some libs (like vuex) need them available as globals anyway, so we would have to include a polyfill as well, which would blow up code size etc.

@LinusBorg I think I can manage to leave IE10 out but I was a bit surprised it didn't work since it was theoretically included in the list of supported browsers.

Given that I can reproduce it successfully without vue, do you think it may be worth opening a ticket in the babel repo? Maybe that combination _is not supposed to work on IE10_

Filed a babel issue, seems like a feature detection error on IE10

https://github.com/babel/babel/issues/7395

@LinusBorg I'm dumb... It's IE11 (the one available on Windows 10)

Looks like a fixing PR has been merged into Babel and should be fixed in the next Babel 7 release.

Closed as it's fixed in Babel 7.0.0-beta.46

I still get the same error with 7.0.0-beta.46

Then you should probably report that in the Babel repo.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eladcandroid picture eladcandroid  路  3Comments

OmgImAlexis picture OmgImAlexis  路  3Comments

wahidrahim picture wahidrahim  路  3Comments

Akryum picture Akryum  路  3Comments

Gonzalo2683 picture Gonzalo2683  路  3Comments