Configuring Shared Dependencies
Learn how the shared option in Module Federation lets host and remote apps share libraries like React, avoiding duplicate downloads and version conflicts.
Configuring Shared Dependencies is a free Micro Frontends Architecture with Module Federation lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Micro Frontends Architecture with Module Federation learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Duplication Problem
Without coordination, a host and each remote would each bundle their own copy of React, Lodash, and other libraries. Users would download the same code many times.
The shared option solves this.
What shared Does
The shared key in ModuleFederationPlugin tells webpack which dependencies should be loaded once and reused across federated apps at run time.
Basic shared Syntax
The simplest form lists package names as an array. Webpack then negotiates a single shared instance at run time.
new ModuleFederationPlugin({
name: "host",
shared: ["react", "react-dom"]
});Object Form for Options
The object form gives fine-grained control per dependency, such as marking it required or singleton.
shared: {
react: { singleton: true, requiredVersion: "^18.0.0" },
"react-dom": { singleton: true }
}The singleton Option
singleton: true forces every app to use ONE instance of the library. This is essential for React, whose hooks break if two copies load at once.
requiredVersion and Negotiation
Each app declares a requiredVersion. At run time Module Federation picks the highest version that satisfies everyone. If versions are incompatible, it warns or falls back.
shared: {
react: { singleton: true, requiredVersion: "^18.2.0" }
}The eager Option
eager: true bundles the shared dependency into the initial chunk instead of loading it asynchronously. Useful for the host shell but increases initial bundle size.
shared: {
react: { singleton: true, eager: true }
}Reading from package.json
To avoid hardcoding versions, you can derive them from your dependencies, keeping shared config in sync with what you actually install.
const deps = require("./package.json").dependencies;
shared: {
react: { singleton: true, requiredVersion: deps.react }
}strictVersion
strictVersion: true makes Module Federation throw instead of falling back when no compatible version is found — surfacing mismatches early during testing.
Common Pitfalls
Watch out for:
- Forgetting
singletonon React, causing hook errors - Mismatched major versions across remotes
- Overusing
eager, bloating the first load
Verifying Sharing Works
Open the browser network tab: if React loads only once across host and remotes, sharing is working. The webpack build log also reports shared-module resolution.
Quick Check
Test your shared-dependency knowledge.
Recap
You configured shared dependencies:
sharedavoids duplicate libraries across apps- Use the object form for per-package control
singletonis critical for React and React-DOMrequiredVersiondrives run-time negotiation- Use
eagerandstrictVersiondeliberately
Good sharing keeps federated apps fast and conflict-free.
Frequently asked questions
Is the “Configuring Shared Dependencies” lesson free?
Yes — the full text of “Configuring Shared Dependencies” is free to read here on the web, and the Micro Frontends Architecture with Module Federation course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Micro Frontends Architecture with Module Federation course, upgrade to CoddyKit PRO.
What will I learn in “Configuring Shared Dependencies”?
Learn how the shared option in Module Federation lets host and remote apps share libraries like React, avoiding duplicate downloads and version conflicts. You practise Micro Frontends Architecture with Module Federation with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Micro Frontends Architecture with Module Federation?
No prior experience is required. Micro Frontends Architecture with Module Federation on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Configuring Shared Dependencies” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Micro Frontends Architecture with Module Federation lesson?
Yes. Every Micro Frontends Architecture with Module Federation lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Webpack Fundamentals Review
- Introducing Module Federation
- Host and Remote Applications
- Configuring Shared Dependencies