Skip to content

"module-import" externals from dynamic chunks are added/hoisted into the main entrypoint instead of the dynamic chunk #20362

@nkalinov

Description

@nkalinov

Bug Description

  1. Webpack is setup with externalsType: 'module-import' and one external: external-lib
  2. There's the main entrypoint without any dependencies and a chunk.js file that does import 'external-lib';
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions