rsbuild: [Bug]: MF breaks the asset path when more than one sub path

Version

System:
    OS: macOS 14.4.1
    CPU: (8) arm64 Apple M1
    Memory: 41.70 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 125.0.6422.141
    Safari: 17.4.1
  npmPackages:
    @rsbuild/core: ^0.7.1 => 0.7.1 
    @rsbuild/plugin-react: ^0.7.1 => 0.7.1

Details

When setting moduleFederation.options and reloading with more than one sub path (.i.e /sub/path) Rsbuild inject assets without the prefix / even setting output.assetPrefix: "/" resulting in a white page.

Commenting or removing the whole moduleFederation from rsbuild config and everything works well.

See the attached Codesandbox and repository to reproduce.

Reproduce link

https://codesandbox.io/p/github/XavierLeTohic/rsbuild-mf-asset-path/main

Reproduce Steps

The repo of the codesandbox is here:

https://github.com/XavierLeTohic/rsbuild-mf-asset-path

To reproduce:

  1. Clone
  2. npm install or yarn install
  3. npm run dev or yarn dev
  4. On http://localhost:5050/example everything will work as expected if you reload
  5. Go to http://localhost:5050/example/sub/path and reload it will be broken
  6. Comment the whole module federation in rsbuild.config.ts and try to reload it’ll work

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 30 (6 by maintainers)

Most upvoted comments

After upgrading to ^1.0.0-alpha.6 it fixed the issue using tools.rspack but the issue remain with the built-in moduleFederation.options

@XavierLeTohic @petrosD93 Thanks a lot guys for your help, I made it easier, I just passed publicPath: ‘auto’ only for remote project,

import { rsbuildConfig } from '@platform/rsbuild-config';
import { defineConfig } from '@rsbuild/core';

// eslint-disable-next-line import/no-relative-packages
import mfConfigs from '../../.deploy/mf.json' assert { type: 'json' };

const env = process.env.ENV;
const appConfig = mfConfigs.mfs.tasks;

if (!appConfig) {
  throw new Error('You dont setup this mf in mf.json!');
}

export default defineConfig(
  rsbuildConfig(
    {
      server: {
        port: appConfig.ports[env],
      },
      tools: {
        rspack: {
          output: {
            publicPath: 'auto',
          },
        },
      },
    },
    {
      name: appConfig.name,
      filename: 'remoteEntry.js',
      exposes: {
        './Tasks': './src/components/Tasks.tsx',
      },
    },
  ),
);

Everything seems to work, locally dev/prod, as well as on amazon, I want to put my setup rsbuild+eslint+prettier+tailwind+mf in a separate monorepo, maybe it will help someone, as I will write here:))

@VictorPulzz have a look at this https://github.com/module-federation/core/issues/3343

I ended up using the base meta tag

I will have a look tomorrow, also why are you spreading the default rsbuild config everywhere? It’s not gonna erase the whole config at the end but apply some kind of patch

this doesn’t seem like an issue anymore. should be safe to close it?

@imzisy this issue also happen with the built-in module federation of rsbuild, not only using the external plugin @module-federation/enhanced/rspack

No certain but I think you can find the plugin of the 1.5 from @rspack/core’s container