Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iterableToArray transitive usages not polyfilled #10625

Closed
RobHannay opened this issue Nov 1, 2019 · 6 comments
Closed

iterableToArray transitive usages not polyfilled #10625

RobHannay opened this issue Nov 1, 2019 · 6 comments
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@RobHannay
Copy link

Bug Report

Current Behavior
When spreading a new Set with core-js 'usage', transitive dependencies are not polyfilled which breaks IE11.

We saw this live when it was not polyfilling 'Array.from', but on this repro it fails earlier because Symbol is also not polyfilled.

If Symbol is added manually it then fails saying it's not an iterable instance, but works fine on Chrome/FF.

Also if you use Array.from(new Set([])); it works fine.

Input Code
Access the Webpack dev server on Internet Explorer and see console errors.
https://babel-corejs-reproduce-set-spread.robhannay.repl.co

Code
https://repl.it/@robhannay/babel-corejs-reproduce-set-spread

Expected behavior/code
Expected the Symbol (or Array.from) 'usage' to be detected from within the iterableToArray method and itself be polyfilled

Babel Configuration (.babelrc, package.json, cli command)

{
  presets: [
    ['@babel/preset-env', {
      modules: false, // Module transpilation is handled by Webpack
      corejs: 3,
      useBuiltIns: 'usage',
    }],
    '@babel/preset-react',
  ],
  plugins: [
    '@babel/plugin-transform-strict-mode',
    '@babel/plugin-proposal-object-rest-spread',
    '@babel/plugin-transform-object-assign',
    '@babel/plugin-syntax-dynamic-import',
    '@babel/plugin-transform-modules-commonjs',
    '@babel/plugin-transform-runtime',
    '@babel/plugin-proposal-class-properties',
  ],
}

Environment

  • Babel version(s): v7.6.4
  • Node/npm version: Node 12 / npm 6 (the repl.it runs on Node 10 but can see the same issue)
  • OS: OSX local / Linux build producted same result
  • Monorepo: no
  • How you are using Babel: loader

Additional context/Screenshots

Screenshot 2019-11-01 at 12 34 12

@babel-bot
Copy link
Collaborator

Hey @RobHannay! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Nov 1, 2019

If you aren't passing a file to Babel (you are excluding it in your webpack config with exclude: /node_modules/), Babel can't transform that code.

I usually suggest transforming the specific node_module with Babel, but since @babel/runtime is a Babel module itself it's really risky.

I suggest aliasing @babel/runtime to @babel/runtime-corejs3 in your webpack config.

@zloirock
Copy link
Member

zloirock commented Nov 1, 2019

I suggest aliasing @babel/runtime to @babel/runtime-corejs3 in your webpack config.

For load both dependencies - core-js and core-js-pure? -) For proper work, in this case, required a version of runtime, compiled with injecting global core-js version.

@dcleao
Copy link

dcleao commented Dec 10, 2019

When you use @babel/plugin-transform-runtime without any options, the default for the corejs is false, which, per the docs means that the babel helpers with use the implementations provided by the @babel/runtime package.

The latter implementation of the babel runtime does not safe-guard any of its code, by importing core-js shims or by other means.

So, I'd say that this is not a bug, but by design.

If you want to include a version of the babel runtime which is safe for operation in certain browsers, you'll have to include one of the alternative provided builds: @babel/runtime-corejs2 or @babel/runtime-corejs3. You can do this by specifying the value 2 or 3 for the option corejs of the @babel/plugin-transform-runtime plugin...

Unfortunately, any of the mentioned builds end up depending and delegating on core-js-pure. If you have other code which is already using the non-pure core-js version, then you'll end up including the "same" core-js code twice (see vuejs/vue-cli#4742).

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Dec 16, 2019

Another option is to transpile @babel/runtime with @babel/preset-env.
We have been discouraging it for two reasons:

  • @babel/plugin-transform-runtime can't be used to transpile @babel/runtime because it will inject circular dependencies. This can be solved by excluding that plugin for this package.
  • @babel/preset-env could have some problems when transpiling the @babel/runtime/helpers/typeof helper with @babel/plugin-transform-typeof-symbol. At this point, your @babel/preset-env targets already exclude that polyfill, otherwise it needs to be explicitly excluded when transpiling this package.

Btw, I will look into how making it safer to transpile @babel/runtime.

@nicolo-ribaudo
Copy link
Member

It's now safe to transpile `@babel/runtime}.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jun 14, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

5 participants