[Breaking change] NormalModuleReplacementPlugin resolves modules using old resource's context in 5.49.0
See original GitHub issueBug report
What is the current behavior? Using the NormalModuleReplacementPlugin, the context in which imports were resolved inside the replacing resource (newResource) was changed in version 5.49.0.
Previously with 5.48.0 and lower, imports were resolved in context specific to the replacing resource (newResource). In 5.49.0 the resolution context remains the same as the original resource.
perhaps issue is caused by this line
https://github.com/webpack/webpack/compare/v5.48.0...v5.49.0#diff-a5db25852bfa94348bb69d94ab95dbef8474d789240b4345cf518e5dd64547ccR249
lib/NormalModule.js
at line 249:
super(type, context || getContext(resource), layer);
If the current behavior is a bug, please provide the steps to reproduce. https://codesandbox.io/s/setup-basic-node-js-server-forked-r1d0c?file=/src/index.js
What is the expected behavior? If this is intended/necessary change, then it should be explicitly stated in the documentation for NormalModuleReplacementPlugin and released as a breaking change. Otherwise, it should resolve imports in replacing resource (newResource) using newResource context.
Other relevant information: webpack version: 5.49.0/5.48.0 Node.js version: v14.16.1 Operating System: MacOS BigSur 11.5.1 Additional tools:
Issue Analytics
- State:
- Created 2 years ago
- Reactions:8
- Comments:8 (3 by maintainers)
Top GitHub Comments
As a workaround it’s needs to set a context of new resource. In my case
NormalModuleReplacementPlugin
resolves regex inafterResolve
phase, so I usecreateData
:It’s worked for me.
Issue was closed because of inactivity.
If you think this is still a valid issue, please file a new issue with additional information.