vue-cli icon indicating copy to clipboard operation
vue-cli copied to clipboard

Promise.prototype.finally() broken in Firefox

Open a1e7de48f89e opened this issue 8 years ago • 25 comments

a1e7de48f89e avatar Jul 31 '18 23:07 a1e7de48f89e

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

  1. The polyfill doesn't include finally
  2. 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.

LinusBorg avatar Aug 01 '18 07:08 LinusBorg

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.

a1e7de48f89e avatar Aug 01 '18 07:08 a1e7de48f89e

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 usage mapping for .then, .catch or .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.

a1e7de48f89e avatar Aug 01 '18 09:08 a1e7de48f89e

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 avatar Aug 03 '18 20:08 yyx990803

@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. :)

a1e7de48f89e avatar Aug 03 '18 21:08 a1e7de48f89e

@yyx990803 什么时候发布版本,这个finally配了好久都没有配置好

zlab avatar Aug 05 '18 01:08 zlab

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.

luizhenriquerdias avatar Aug 23 '18 17:08 luizhenriquerdias

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`

eyar avatar Oct 03 '18 10:10 eyar

Im still missing the finally on firefox..

using ['@vue/app', { useBuiltIns: 'entry' }] fails to build with Unknown option: .useBuiltIns.

mrodal avatar Jan 07 '19 18:01 mrodal

It's a nested array:

[['@vue/app', { useBuiltIns: 'entry' }]]

LinusBorg avatar Jan 07 '19 20:01 LinusBorg

@LinusBorg yes, thanks, that fixed the build error! but I still dont have the finally on promises :\

mrodal avatar Jan 09 '19 19:01 mrodal

can this issue be reopened? its still happening 😕

mrodal avatar Jan 21 '19 13:01 mrodal

@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.

LinusBorg avatar Jan 21 '19 15:01 LinusBorg

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

mrodal avatar Jan 21 '19 15:01 mrodal

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.

LinusBorg avatar Jan 21 '19 15:01 LinusBorg

true, sorry, I also upgraded vue cli service and plugins from 3.0.3 to 3.0.4

mrodal avatar Jan 21 '19 15:01 mrodal

@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.

a1e7de48f89e avatar Jan 21 '19 15:01 a1e7de48f89e

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

pmochine avatar Feb 04 '19 18:02 pmochine

@mserajnik in Which Vue cli version were this bug had Fixed ?

amagdyh avatar Mar 20 '19 15:03 amagdyh

@ahussein3 This has been fixed in v3.0.0-rc.11 in August 2018.

a1e7de48f89e avatar Mar 20 '19 16:03 a1e7de48f89e