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

After adding the moduleFederation configuration in rsbuild.config.ts, there is a problem with the import code generated by preview.ejs. #91

Open
lyj1994 opened this issue Sep 13, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@lyj1994
Copy link

lyj1994 commented Sep 13, 2024

rsbuild.config.ts

import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';
import { pluginSass } from '@rsbuild/plugin-sass';

export default defineConfig({
  plugins: [pluginReact(), pluginSass()],
  moduleFederation: {
    options: {
      name: 'host',
      remotes: {},
      shared: ['react', 'react-dom', 'lodash', 'moment'].reduce((acc, curr) => {
        acc[curr] = {
          singleton: true,
          requiredVersion: false,
        };
        return acc;
      }, {}),
    },
  },
});

image
error: Uncaught TypeError: Failed to resolve module specifier "static/js/runtime~main.iframe.bundle.js". Relative references must start with either "/", "./", or "../".

After delete moduleFederation:
image

I found that preview.ejs uses htmlWebpackPlugin to inject file names.
https://github.com/rspack-contrib/storybook-rsbuild/blob/main/packages/builder-rsbuild/templates/preview.ejs#L76

<script type="module">
      import './sb-preview/runtime.js';
      <% htmlWebpackPlugin.files.js.forEach(file => { %>
      import '<%= file %>';
 <% }); %>

Only when moduleFederation is turned on will there be this problem.

@fi3ework
Copy link
Member

fi3ework commented Sep 14, 2024

I found that preview.ejs uses htmlWebpackPlugin to inject file names.

@lyj1994 This is by design to inject the entry to load the Storybook application. I think the issue is when module federation is configured. The assetsPrefix is changed from / to ``. Could you provide a minimal reproduction to address this issue?

@lyj1994
Copy link
Author

lyj1994 commented Sep 19, 2024

https://codesandbox.io/p/github/rspack-contrib/rsbuild-codesandbox-example/csb-p2t747/draft/stupefied-zeh

I have written an example with codesanbox. Please help me take a look at this problem.

@fi3ework fi3ework added the bug Something isn't working label Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants