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

Fix disappearing polyfills when conflicting versions of preset are used #12554

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ertrzyiks
Copy link

@ertrzyiks ertrzyiks commented Dec 23, 2020

Q                       A
Fixed Issues? Fixes #12545
Patch: Bug Fix? Yes
Major: Breaking Change? No
Minor: New Feature? No
Tests Added + Pass? Yes
Documentation PR Link No
Any Dependency Changes? No
License MIT

If the preset-env is applied twice and

The core-js polyfills are removed from the bundle.

Example of breaking configuration can be found in the demo project:
https://github.com/ertrzyiks/babel-loader-lost-polyfills-demo

The demo project uses preset-env and preset-react-app. The minimal configuration causing polyfills to disappear is the following:

presets: [
  [
    // => Found "@babel/preset-env@7.12.11"
    require('@babel/preset-env').default,
    { corejs: 3, useBuiltIns: 'entry' }
  ],
  [
    //=> Found "babel-preset-react-app#@babel/preset-env@7.12.1"
    require('babel-preset-react-app/node_modules/@babel/preset-env').default, 
    { corejs: 3, useBuiltIns: 'entry' }
  ],
]

Updated snapshots

The two updated snapshots are for cases when the input importing specific files like

import 'core-js/modules/es.symbol';
import 'core-js/modules/es.object.from-entries';
import 'core-js/modules/esnext.string.replace-all';

so judging by the purpose of the original PR introducing the extensions won't be problematic: the original imports are kept untouched. No autogenerated code without .js extension though.

@babel-bot
Copy link
Collaborator

babel-bot commented Dec 23, 2020

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/36836/

@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 23, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 28f6547:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

import "core-js/modules/es.object.from-entries.js";
import "core-js/modules/esnext.string.replace-all.js";
import 'core-js/modules/es.object.from-entries';
import 'core-js/modules/esnext.string.replace-all';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add test cases when input file contains core-js imports ending with .js?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 👍 is this single scenario enough or you had more cases in mind?
28f6547

@nicolo-ribaudo nicolo-ribaudo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Jan 7, 2021
@nicolo-ribaudo
Copy link
Member

It's possible that this will also be fixed by #12583

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Jan 9, 2021

@ertrzyiks #12583 doesn't fix this bug, but since we are replacing our polyfills injection logic I have copied this PR to babel/babel-polyfills#56 (also, I figured out how to properly add a test).

Thanks for the help anyway, and I set you as the author of the commits in the other repo!

@ertrzyiks
Copy link
Author

@nicolo-ribaudo makes sense, thanks for letting me know and all the help with my very first PR. It was unexpectedly easy to work with such complex codebase. We can close this PR, right?

@nicolo-ribaudo
Copy link
Member

I don't know if #12583 will be merged before the next release, so I think it's better to keep this open for now.

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 7.13.0 release that replaces this transform is taking way longer than expected, and this PR is a good fix until 7.13.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[preset-env] all the core-js imports are removed
4 participants