-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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
[Feature request] Port resolveWeak to javascript/esm #18633
Comments
What is |
Sorry, I mean
Does it mean that code that today is written with require.requireWeak('./OtherComponent.js') can be migrated to this in ESM without anything more to handle? import.meta.webpackContext('./OtherComponent.js', { mode: "weak" }); |
Let's close in favor #16693, we don't support |
Feature request
What is the expected behavior?
CommonJS code allows the usage of
require
, and so the corresponding webpack rule typejavascript/auto
will transformrequire.resolveWeak
into the corresponding runtime code.ESM code does not allow the usage of require, and so
javascript/esm
type does not transformrequire.resolveWeak
, as we don't expect to seerequire
in this context.Still, libraries like
@lodable/components
orreact-loadable
leverage thisrequire.resolveWeak
capability to implement their code-splitting abstractions. When generating ESM code that use them, we end up withrequire.resolveWeak
inside ESM, which webpack does not understand by default. This creates runtime failures.What is motivation or use case for adding/changing the behavior?
As far as I know multiple options can mitigate the issue:
not using ESM
not using those libraries
forcing
javascript/auto
for the concerned ESM files (see issue here)No option is perfect here:
@loadable/server
)How should this be implemented in your opinion?
Webpack started to leverage
import.meta
, which is free to use, to implementimport.meta.webpackContext
, for example.Can we imagine following this path to port the
resolveWeak
capability tojavascript/esm
also? This is also mentioned in this comment.This way, code historically leveraging
require.resolveWeak
will be able to migrate toimport.meta.resolveWeak
or something similar when bundled in ESM.Are you willing to work on this yourself?
I can help, but I've never contributed to webpack so this might be a very challenging tasks for me 😅
I'm probably better suited to do update PRs on https://github.com/gregberge/loadable-components/ and https://github.com/swc-project (loadable plugin).
The text was updated successfully, but these errors were encountered: