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

Disable Babel in the @babel/runtime package. #11047

Closed
1 task
aradzie opened this issue Jan 23, 2020 · 10 comments · Fixed by #11049
Closed
1 task

Disable Babel in the @babel/runtime package. #11047

aradzie opened this issue Jan 23, 2020 · 10 comments · Fixed by #11049
Labels
i: enhancement i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@aradzie
Copy link

aradzie commented Jan 23, 2020

Feature Request

  • I would like to work on this feature!

Is your feature request related to a problem? Please describe.
The combination of Webpack with Babel may cause a problem such as #10996 if the @babel/runtime package is not explicitly excluded from Babel. This package contains helper functions which must not be transpiled by Babel. However, if care is not taken to exclude, Webpack will apply Babel to @babel/runtime resulting in a broken bundle.

For example, the Babel runtime contains helper function _typeof(obj) which replaces the typeof operator to recognize Symbols. This function contains few typeof operators internally, and when transpiled by Babel these operators are replaced with the same helper function. Whoops!

Describe the solution you'd like
If Babel contains any exclusion mechanism, it must be applied to package @babel/runtime to prevent the situations as the above.

@babel-bot
Copy link
Collaborator

Hey @aradzie! 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

I think that there is still value in transpiling it sometimes, for example to include polyfills for the functions used by the helpers.
I think we could so something ad-hoc for the type of helper.

@aradzie
Copy link
Author

aradzie commented Jan 23, 2020

Looking at the plugin source code it seems like it already tries to detect the situation when the typeof helper is applied to itself. Is this the case? If so, then that code probably is not working properly and needs to be fixed instead of this issue.

@wolf-ben
Copy link

wolf-ben commented Jan 23, 2020

To me it seems Webpack already tries to take care of the case that another typeof function exists by reassigning it to

var _typeof2 = __webpack_require__(/* @babel/runtimehelpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js");

before using this new function to do the work. But somehow this doesn‘t get the job done: The error _typeof2 is not a function is thrown.
Let me know if I‘m on the right track...

@aradzie
Copy link
Author

aradzie commented Jan 23, 2020

@wolf-benjamin No, please take a look at the imported module id. It is the same as the module id in which the helper function is declared. The module imports from itself! And this is the result of application of Babel to its own helper function.

PS I am preparing a small project to demonstrate the bug.

@wolf-ben
Copy link

Btw, adding ignore/exclude commands for @babel/runtime in babel.config.js seems not to work.

@aradzie
Copy link
Author

aradzie commented Jan 23, 2020

And here is the repository I created to demonstrate this issue -- https://github.com/aradzie/babel-typeof-bug

@nicolo-ribaudo
Copy link
Member

@aradzie Thanks! I didn't know that we already tried to prevent this.

@aradzie
Copy link
Author

aradzie commented Jan 23, 2020

@nicolo-ribaudo Unfortunately this seems to be a recurring bug.
As @soryy708 mentioned in #10996, these issues may be related:
#2954
#3737
https://swizec.com/blog/dont-worry-its-a-compiler-bug/swizec/6764

@nicolo-ribaudo
Copy link
Member

I'm preparing a PR

@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 Apr 28, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: enhancement i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants