Webpack Module Federation: Singleton Dependency Conflict Resolution
0 reputation · 13 Aug 2022, 19:53 UTC
Webpack 5 introduces Module Federation to enable runtime code sharing between independent builds. A critical aspect of this architecture is the shared configuration, which prevents redundant library loading by negotiating versions between the host and remote containers.
When a library is marked as a singleton, Webpack ensures only one instance of that dependency exists in the runtime environment. However, uncertainty arises when multiple federated modules require incompatible version ranges of a singleton library, particularly when strictVersion is enabled.
The goal is to maintain a single instance of a state-management or UI library while ensuring that version mismatches do not cause silent failures or runtime crashes.
- How does Webpack resolve the singleton conflict when two remotes provide incompatible versions that both satisfy the host's requirements?
- What is the expected behavior of the runtime when
strictVersion: trueis set and no compatible singleton version is available across the federated network?