Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for storybook / rsbuild / module federation setup #30

Open
nate-summercook opened this issue Jun 26, 2024 · 5 comments
Open

Support for storybook / rsbuild / module federation setup #30

nate-summercook opened this issue Jun 26, 2024 · 5 comments
Labels
Rspack Rspack related issue

Comments

@nate-summercook
Copy link

Hello there

I've got a project that makes use of module federation (just migrated from webpack to rsbuild) but now I can't get storybook to properly start up with my module federation dependency configured.
Here's the relevant part of my storybook / rsbuild config:

{
...
framework: 'storybook-react-rsbuild',
  rsbuildFinal: (config) => {
    return mergeRsbuildConfig(config, {
      plugins: [pluginReact()],
      moduleFederation: {
        options: {
          name: '_my_library',
          filename: '_my_library.js',
          remotes: {
            _my_remote: '_my_remote@http://localhost:3050/_my_remote.js',
          },
          shared: {
            react: { singleton: true },
            'react-dom': { singleton: true },
          },
        },
      },
    });
  },
}

I don't think this library supports this usecase yet, as I'm getting errors after starting up the app.

The loadShareSync function was unable to load react. The react could not be found in _my_library.
        Possible reasons for failure: 

        1. The react share was registered with the 'get' attribute, but loadShare was not used beforehand.

        2. The react share was not registered with the 'lib' attribute.

When using webpack, I've managed to get module federation imports working by using storybook-module-federation. I suspect that this doesn't work yet because of the missing initial dynamic import. That seems to have been the issue with this similar issue here
So if I'm doing something wrong in using module federation together with storybook / rsbuild, please provide a working example or some guidance here. If it's not yet supported at all, please consider implementing it soon ❤️

@fi3ework
Copy link
Member

The plugin is using webpack-virtual-modules https://github.com/robdonn/storybook-module-federation/blob/main/src/main.ts#L1 here, which is not supported by Rspack as of now (see https://www.rspack.dev/api/javascript-api#custom-file-systems)

@fi3ework fi3ework added the Rspack Rspack related issue label Jul 17, 2024
@nate-summercook
Copy link
Author

What does that mean in the end? Nothing is being done about this currently and we have to wait for rspack to support what is needed to get this working?

@artieeez
Copy link

I was able to get it working by injecting the dynamic import into the entry point of my bundle, similar to how it's done in storybook-module-federation, but using the rspack-plugin-virtual-module instead.

I’m planning to create a PR for storybook-module-federation to add support for Rspack. However, it might take some time as this will be my first contribution to open source. Feel free to reach out if you need more clarification or if you'd like to help with the PR.

@fi3ework
Copy link
Member

@artieeez Nice try, while Rspack is trying to implement the built-in virtual module support in the near future. I think we could wait for that and contribute it to https://github.com/robdonn/storybook-module-federation. At the moment, may I know how you're implementing this now, but forking or some other ways?

@artieeez
Copy link

@fi3ework , understood. I’ll hold off on that plan for now.
Here’s how I implemented it:
https://github.com/artieeez/storybook-rsbuild-virtual-module-example

@nate-summercook , feel free to use this approach until a more robust solution becomes available.

A quick note: I attempted using the Hoisted Runtime, but unfortunately, it didn’t work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rspack Rspack related issue
Projects
None yet
Development

No branches or pull requests

3 participants