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

babel transfrom runtime incompatible with url loader #10561

Closed
samMeow opened this issue Oct 16, 2019 · 5 comments · Fixed by #10574
Closed

babel transfrom runtime incompatible with url loader #10561

samMeow opened this issue Oct 16, 2019 · 5 comments · Fixed by #10574
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@samMeow
Copy link
Contributor

samMeow commented Oct 16, 2019

Bug Report

Current Behavior
Babel dynamic import _interopRequireWildcard function fail if imported obj/ modules is pure string (e.g. base64 encoded image), because cache (WeakMap) doesn't accept string as key (only accept object).

Input Code
Ref: #10161

Expected behavior/code
_interopRequireWildcard should take care string module (url-loader/file-loader) also.

Environment

  • @babel/core": "^7.6.4"
  • node 10.15
  • @babel/plugin-transform-runtime: 7.6.2
  • url-loader : ^2.2.0

Possible Solution
Consider a different cache mechanism (e.g. Map/ no cache for string)

Screenshot 2019-10-16 at 2 15 17 PM

@babel-bot
Copy link
Collaborator

Hey @samMeow! 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 Oct 16, 2019

If you are using webpack you shouldn't transpile modules: it will just lead to a less optimized output.

But yes, that last if should be if (cache && typeof obj === "object").

@samMeow
Copy link
Contributor Author

samMeow commented Oct 16, 2019

Thanks for quick response. If the direction is to only cache objects, we can simply return at the top?
if (typeof obj !== 'object') return obj and skip those caching part?

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Oct 16, 2019

Yeah, but it should return { default: obj } instead.

@theKashey
Copy link

theKashey commented Oct 19, 2019

Yeah, but it should return { default: obj } instead.

Why? It seems to me, that it shall return a clone of the object, with additional default:obj field.

nicolo-ribaudo pushed a commit that referenced this issue Oct 19, 2019
* fix: [#10561] _interopRequireWildcard should cache object only

* fix: narrow down cache restriction to object/function type

* test: add interop require null module case
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jan 18, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug 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.

5 participants