Feature/non webpack require warning and concatenated module population #19441
+94
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 toimport{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__
torequire
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 throwUncaught 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.
__non_webpack_require__
usage in target web__WEBPACK_EXTERNAL_createRequire
fragment when__non_webpack_require__
used inConcatenatedModule
Did you add tests for your changes?
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 beforeWhat 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'.