question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Array methods `flat` and `flatMap` are not polyfilled

See original GitHub issue

Version

3.6.3

Reproduction link

https://github.com/runarberg/vue-cli-minimal-example

Environment info

npx @vue/cli info

Environment Info:

  System:
    OS: Linux 4.15 Ubuntu 18.04.2 LTS (Bionic Beaver)
    CPU: (4) x64 Intel(R) Core(TM) i7-7600U CPU @ 2.80GHz
  Binaries:
    Node: 11.2.0 - ~/.nvm/versions/node/v11.2.0/bin/node
    Yarn: Not Found
    npm: 6.4.1 - ~/.nvm/versions/node/v11.2.0/bin/npm
  Browsers:
    Chrome: Not Found
    Firefox: 66.0.2
  npmPackages:
    @vue/babel-helper-vue-jsx-merge-props:  1.0.0-beta.3 
    @vue/babel-plugin-transform-vue-jsx:  1.0.0-beta.3 
    @vue/babel-preset-app:  3.6.0 
    @vue/babel-preset-jsx:  1.0.0-beta.3 
    @vue/babel-sugar-functional-vue:  1.0.0-beta.3 
    @vue/babel-sugar-inject-h:  1.0.0-beta.3 
    @vue/babel-sugar-v-model:  1.0.0-beta.3 
    @vue/babel-sugar-v-on:  1.0.0-beta.3 
    @vue/cli-overlay:  3.6.0 
    @vue/cli-plugin-babel: ^3.6.0 => 3.6.0 
    @vue/cli-plugin-eslint: ^3.6.0 => 3.6.0 
    @vue/cli-service: ^3.6.0 => 3.6.0 
    @vue/cli-shared-utils:  3.6.0 
    @vue/component-compiler-utils:  2.6.0 
    @vue/preload-webpack-plugin:  1.1.0 
    @vue/web-component-wrapper:  1.2.0 
    eslint-plugin-vue: ^5.0.0 => 5.2.2 
    vue: ^2.6.10 => 2.6.10 
    vue-eslint-parser:  2.0.3 
    vue-hot-reload-api:  2.3.3 
    vue-loader:  15.7.0 
    vue-style-loader:  4.1.2 
    vue-template-compiler: ^2.5.21 => 2.6.10 
    vue-template-es2015-compiler:  1.9.1 
  npmGlobalPackages:
    @vue/cli: Not Found

Steps to reproduce

  1. Create a new vue project with babel plugin
  2. In your app use the flat or flatMap array methods

What is expected?

These array methods should be polyfilled

What is actually happening?

They are not polyfilled


  • Open your app in Chrome, Firefox or Safari and see it working.
  • Open it in Edge and see an error message:
[Vue warn]: Error in render: "TypeError: Object doesn't support property or method 'flat'"
TypeError: Object doesn't support property or method 'flat'

Note that babel is configured to polyfill any method that is used, this includes Array.from in the above example.

Also note that Array.prototype.{flat,flatMap} were approved for stage 4 in at TC-39 last January and have been moved to stable in core-js.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
gavvvrcommented, Apr 24, 2019

Just noticed my app can’t work in IE because of missing flatMap.

Adding

import “core-js/fn/array/flat-map”;

to main.js solved the problem for me

4reactions
sodateacommented, Apr 18, 2019
  1. It’s only stable in core-js 3, while we use core-js 2
  2. https://github.com/babel/website/blob/master/docs/plugin-transform-runtime.md#core-js-aliasing

    Instance methods such as “foobar”.includes(“foo”) will only work when using corejs: 3.

Will be fixed once we upgraded to core-js v3 in Vue CLI v4.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Array.prototype.flatMap() - JavaScript - MDN Web Docs
A function to execute for each element in the array. It should return an array containing new elements of the new array, or...
Read more >
flatMap method over array - (flatMap is not a function)
The flatMap() method first maps each element using a mapping function, then flattens the result into a new array. It is identical to...
Read more >
Flatten Arrays in Vanilla JavaScript with flat() and flatMap()
An overview of two new methods available on the Array prototype in JavaScript: flat and flatMap.
Read more >
JavaScript Array Methods | flat and flatMap - YouTube
Learn how to flatten arrays easily with the flat and flatMap array methods introduced in ES2019. Pretty useful for squashing those nested ...
Read more >
How to Use the flat() and flatMap() Methods to Flatten Arrays ...
In JavaScript and likewise in other programming languages, the right word to use is index and not position. JavaScript arrays can contain ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found