Skip to content

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

Open
@lyj1994

Description

@lyj1994

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions