question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using storybook as module federation host is not possible

See original GitHub issue

Describe 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.

image

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:open
  • Created 2 years ago
  • Reactions:3
  • Comments:6

github_iconTop GitHub Comments

4reactions
robdonncommented, Sep 4, 2021

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

0reactions
richardklotzcommented, Sep 3, 2021

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found