Skip to content

Feature/non webpack require warning and concatenated module population #19441

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

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

Conversation

suguanYang
Copy link

@suguanYang suguanYang commented Apr 19, 2025

What kind of change does this PR introduce?
Related Issue: #17971

When bundling __non_webpack_require__ with ESModule in web, the runtime will broken because of webpack will transform it to import{createRequire as __WEBPACK_EXTERNAL_createRequire} from"module", this should only be used in target: node.

Its hard to define the behavior of the require in web ESModule context, one solution is just transform this __non_webpack_require__ to require just as non-module format for web, since in ESModule a global require is still avaliable for user to define, and if not, the runtime will throw Uncaught ReferenceError: require is not defined as soon as possible, this gives the developer a chance to find the issue at early stage.

Maybe for now a wanrning is enough for such case as @alexander-akait said.

  • Feature: add warning for __non_webpack_require__ usage in target web
  • Bugfix: missing __WEBPACK_EXTERNAL_createRequire fragment when __non_webpack_require__ used in ConcatenatedModule

Did you add tests for your changes?

  • Yes 💯

Does this PR introduce a breaking change?

This may cause break change for changes in ConcatenatedModule since there is no __WEBPACK_EXTERNAL_createRequire added in the output modue before

What needs to be documented once your changes are merged?
We need to notice the module variable __non_webpack_require__ shouldn't be used in context 'target: web' and 'output: module'.

Copy link

linux-foundation-easycla bot commented Apr 19, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@suguanYang suguanYang marked this pull request as ready for review April 19, 2025 08:24
Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Looks good, let's add a test case and we can merge, thank you

@suguanYang
Copy link
Author

Looks good, let's add a test case and we can merge, thank you

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants