Using storybook as module federation host is not possible
See original GitHub issueDescribe the bug
If I add Module Federation plugin to webpack config, the storybook breaks with error: Shared module is not available for eager consumption: webpack/sharing/consume/default/react/react
.
This happens when there’s no import('./bootstrap')
in entry point, see webpack docs: https://webpack.js.org/concepts/module-federation/#troubleshooting
To Reproduce
Run
$ yarn add webpack @storybook/builder-webpack5 -D
Add following code to .storybook/main.js
:
const { ModuleFederationPlugin } = require("webpack").container;
module.exports = {
stories: ["../src/**/*.stories.js"],
addons: [
"@storybook/addon-actions",
"@storybook/addon-links"
],
core: {
builder: "webpack5"
},
webpackFinal: async (config) => {
config.plugins.push(
new ModuleFederationPlugin({
name: "ringcentral_whiteboard_storybook",
shared: {
react: {
import: "react", // the "react" package will be used a provided and fallback module
shareKey: "react", // under this name the shared module will be placed in the share scope
shareScope: "default", // share scope with this name will be used
singleton: true // only a single version of the shared module is allowed},
},
"react-dom": { singleton: true }
}
})
);
return config;
}
};
Here’s the codesandbox: https://codesandbox.io/s/storybook-module-federation-5v2n3
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:6
Top Results From Across the Web
Federated Design Systems with Storybook - Xolvio
An exploration into how Storybook-based design systems can be used to distribute component ... Right now versions are not supported in Webpack Federation....
Read more >Webpack module federation is not working with eager shared ...
It seems like the main reason of why it failed initially was that remoteEntry.js file was loaded after the code that actually runs...
Read more >Zack Jackson on Twitter: "Storybook and Module Federation is ...
Storybook and Module Federation is a thing. @sam_hatoum. very very nice job. ... What happens if you mix @storybookjs with @webpack Federation?
Read more >Module Federation Series Part 1: A Little in-depth
If an application consuming a federated module does not have a dependency ... In Module federation shell(host) is called ContainerReferencePlugin while ...
Read more >Micro-Frontends using Module Federation, presets for React ...
Micro-Frontends using Module Federation, presets for React and Storybook, TypeScript compiler plugins, and more in Nx 12.8!
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There is now a library on NPM for enabling module federation for Storybook. The GitHub repo has examples for using Storybook as either a host or a remote.
https://github.com/robdonn/storybook-module-federation
Not Ideal, but I got around it for now by adding react and react-dom to webpack externals, then loaded them globally in preview-head.html