Promise.prototype.finally() broken in Firefox
Hm, I remember coming across something like this a while ago when building a prototype with beta.3 or something.
We include a Promise polyfill with vue-cli by default. Maybe we have a weird situation where
- The polyfill doesn't include
finally - in Firefox, the polyfill is installed even though it should be skipped as FF has native Promises already
If so, 1.) would be an issue to solve in vue-cli, if 2.), which would be a problem with babel-polyfill / core.js, can't be resolved quickly.
According to this there's also es.promise.finally, which I tried to add the following way:
module.exports = {
presets: [
['@vue/app', {
polyfills: ['es6.promise', 'es6.promise.finally', 'es6.array.iterator']
}]
]
}
Hoewever, this throws an error on build:
Cannot read property 'android' of undefined (While processing
: "/fake/path/vue-cli-promise-finally/node_modules/@vue/babel-preset-app/index.js")
at targetEnvironments.filter.environment (/fake/path/vue-cli-promise-finally/node_modules/@babel/preset-env/lib/index.js:75:
16)
Might also be related to this, will try that workaround out later.
Doing the following seems to work:
// babel.config.js
module.exports = {
presets: [
['@vue/app', { useBuiltIns: 'entry' }]
]
}
// src/main.js
import '@babel/polyfill'
[…]
It does increase the bundle size a bit (as expected), but that's not really an issue.
According to this comment from Brian Ng:
Yep, there's currently no
usagemapping for.then,.catchor.finally.
So, issue solved for me. Do you think you could mention this limitation of having useBuiltIns in usage mode somewhere in the readme of @vue/babel-preset-app? I know that's an issue/limitation with @babel/preset-env itself, but given that @vue/cli is pretty much zero config by default and very beginner-friendly for people who haven't worked with webpack/Babel/etc. before, this is likely one of the first places they'd look if they encountered such an issue.
This is an issue in core-js - its promise polyfill replaces the native Promise in Firefox, however according to author of core-js, it is doing it because Firefox's Promise implementation somehow fails a subclassing check so is technically not spec-compliant.
For now I've included es7.promise.finally by default to fix this in Vue CLI.
@yyx990803
Thanks, I think that's a decent solution for now.
I had forgotten Promise.prototype.finally() is not part of the ES6 spec, so the way I've tried to include the polyfill before (via es6.promise.finally) obviously didn't work in hindsight. Time to switch useBuiltins back to the default usage mode. :)
@yyx990803
什么时候发布版本,这个finally配了好久都没有配置好
Sorry to comment on a closed topic but I'm getting an error relative to the subject.
`This dependency was not found:
- core-js/modules/es7.promise.finally in ./src/main.js
To install it, you can run: npm install --save core-js/modules/es7.promise.finally`
I'm getting the error AFTER the rc10, so I had to fix the version in rc10.
Happens to me also after installing vue-styled-components
`This dependency was not found:
core-js/modules/es7.promise.finally in ./src/main.js To install it, you can run: npm install --save core-js/modules/es7.promise.finally`
Im still missing the finally on firefox..
using ['@vue/app', { useBuiltIns: 'entry' }] fails to build with Unknown option: .useBuiltIns.
It's a nested array:
[['@vue/app', { useBuiltIns: 'entry' }]]
@LinusBorg yes, thanks, that fixed the build error! but I still dont have the finally on promises :\
can this issue be reopened? its still happening 😕
@mrodal if it's still happening for your, open a new issue with reproduction and a reference to this issue here.
I won't reopen this old one, it's outdated and I can't tell if the problem you describe actually exists in the way you say it does.
Its fixed, I upgraded vue to the latest version. Its weird, because the version I had (2.5.17) had the changes made by @yyx990803.. but anyways, its working now, thanks @mserajnik and @LinusBorg
I think you are confusing Vue ( currently 2.5.18) with vue-cli (3.3.0).
The latter is responsible for injecting the polyfill. The Vue version isn't important for that.
true, sorry, I also upgraded vue cli service and plugins from 3.0.3 to 3.0.4
@LinusBorg
Actually, latest Vue is 2.5.22.
@mrodal
Latest version of @vue/cli-plugin-babel and @vue/cli-service is 3.3.0; if you encounter any issues when building, I'd always recommend upgrading every dev dependency to the latest version (if you can) – chances are, the issue has been fixed. And as long as it's not a new major version, the chance of your build environment breaking should be pretty slim (and you can always roll back anyway if something goes wrong).
You can use a tool like updates to check for newer versions.
I'm a noobie, but have the same issue but without having vue-cli installed. I come from Laravel. Anyhow, here is one open question in StackOverflow. Perhaps someone can help me :)
Edit 1: The issue lies in my installed package. Somehow it overwrites my promise
@mserajnik in Which Vue cli version were this bug had Fixed ?
@ahussein3 This has been fixed in v3.0.0-rc.11 in August 2018.