Skip to content

Lesson 4 of 9 · 25m

Shared Dependencies Without the Versioning Trap

Singletons, duplicate framework copies, import maps, and dependency policy — how to share enough without recreating the monolith at runtime.

Nothing torpedoes runtime micro-frontends faster than dependency ambiguity. The symptoms look random: React invalid hook call errors, two copies of a state library fighting over subscriptions, a design system whose context exists twice, or a 700 KB jump in initial load because every remote ships its own framework.

The goal is not "share everything." The goal is to deliberately classify each dependency as singleton, shared compatible, or private.

Singletons are for libraries with hidden global state

React is the classic example. Two copies of React in one tree break hooks because hook state is tied to the instance that created it:

Warning: Invalid hook call. Hooks can only be called inside the body of a function component.

When you see this in a federated app, suspect duplicate React before touching component code. Module Federation expresses the rule directly:

shared: { react: { singleton: true, strictVersion: true, requiredVersion: "^19.1.0" } }

A singleton is a runtime promise: exactly one copy exists, and everyone must agree on the compatible range.

Shared compatible dependencies can diverge within a range

A date library or utility package often does not need to be singleton. Mark it shared when deduplication is valuable but independent copies are not catastrophic:

shared: { zod: { requiredVersion: "^3.24.0" }, "@acme/design-tokens": { singleton: true } }

The second one is singleton because tokens often flow through context or CSS custom properties established once by the shell. Ask not "is this package large?" but "does correctness depend on identity?"

Import maps are the framework-independent version

Native import maps give browsers a shared resolution table:

<script type="importmap">
{"imports": {"react": "https://cdn.acme.io/vendor/react-19.1.0.js",
             "@acme/design-system": "https://cdn.acme.io/design-system/7.4.2/index.js"}}
</script>

This is attractive in multi-framework estates because the contract lives outside any one bundler. The tradeoff is cache and rollout coordination: updating the map is itself a deployment.

Private dependencies preserve autonomy

Teams should not need a federation-wide meeting to upgrade a charting library used in one dashboard. Keep dependencies private unless sharing creates a measurable benefit. Bundle size matters, but so does decision latency.

Set policy before the incident

Create a small dependency registry owned by the frontend platform group:

singleton: [react, react-dom, "@acme/design-tokens"]
shared-compatible: [zod, date-fns]
private-by-default: true

Review additions. A singleton list with forty entries is a hidden monolith.

Field notes

  • Duplicate framework copies cause correctness bugs, not just bundle bloat.
  • Strict singleton versioning improves safety but reduces independent upgrades; that tension is the architecture in miniature.
  • Do not share internal state libraries across independently deployed teams unless you are prepared to version their runtime behavior.
  • Measure bundles after federation. It is common to save nothing because every remote still carries overlapping dependencies.

Was this lesson helpful?

Sign in to rate