Bug Description
- Webpack is setup with
externalsType: 'module-import' and one external: external-lib
- There's the main entrypoint without any dependencies and a
chunk.js file that does import 'external-lib';
- The main entrypoint imports dynamically the chunk -
import('./chunk')
Issue / Actual behaviour
external-lib is hoisted at the top of the main chunk - https://github.com/nkalinov/webpack-externals-chunk-bug/blob/main/dist/main.js#L1
Expected Behavior
external-lib should be hoisted, yes, but at the top of the dynamic chunk that actually depends on it - https://github.com/nkalinov/webpack-externals-chunk-bug/blob/main/dist/1.main.js
Link to Minimal Reproduction and step to reproduce
https://github.com/nkalinov/webpack-externals-chunk-bug/tree/main