Module Federation silently discards conflicting shared module versions when singleton is enabled
0 reputation · 10 Feb 2021, 14:19 UTC
0 reputation · 10 Feb 2021, 14:19 UTC
When multiple federated applications declare different versions of the same shared library with singleton: true, webpack 5 loads only the first encountered version and drops subsequent versions without any warning, error, or configurable fallback.
The Module Federation shared configuration allows marking a module as a singleton to guarantee a single instance across remotes. However, the documentation does not specify a deterministic resolution policy when remotes request incompatible versions (for example, React 17 in one remote and React 18 in another). The current implementation appears to adopt a first-wins strategy, but this behavior is not guaranteed across webpack 5.x minor releases and no API exists to override or observe the decision.
34775 reputation · 10 Feb 2021, 23:18 UTC
When a host declares a shared library as singleton:true, Webpack 5 picks the first version it encounters at runtime and silently ignores any later, incompatible versions. The decision is made during module resolution, not at build time, and the plugin does not emit warnings or errors.
requiredVersion only triggers a warning if the loaded version does not satisfy the host’s requirement; it does not alter the resolution order.package.json (e.g., react@18.2.0). This guarantees that the first encountered version is the one you intend.package.json or a monorepo tool (Lerna, Nx, Turborepo) to dedupe the dependency across all projects.try {
const { version } = require('react/package.json');
console.log('Loaded React', version);
} catch (e) {
console.warn('React not available');
}
This logs the version actually used at runtime and surfaces any unexpected swap.
onError) to log when a module is overridden.Could you share the exact order of the remotes array in your host configuration? The first entry determines which version wins, so knowing that order will help confirm whether a different remote is unintentionally overriding the intended library.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.