web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
10.05k stars 573 forks source link

[Bug]: __webpack_public_path__ runtime does not function correctly when using Webpack Module Federation. #8436

Closed cairon666 closed 1 week ago

cairon666 commented 1 week ago

Version

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Pro
    Memory: 172.09 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 130.0.6723.117
    Safari: 17.5
  npmPackages:
    @rsbuild/core: ^1.1.1 => 1.1.1 
    @rsbuild/plugin-react: ^1.0.7 => 1.0.7

Details

When my remote app uses Webpack, webpack_public_path is set to the path of the remoteEntry.js import. When my remote app uses RSBuild, webpack_public_path is set to window.location.origin.

As a result, when the remote app is loaded with RSBuild, the component is not loaded from the correct path.

The main application is located at http://localhost:1000/, where the host MWF is running. I need to load BugRsbuild, which is located at http://localhost:1000/static/bug-rsbuild/remoteEntry.js. After loading the remoteEntry.js, I expect that the remaining components will be loaded from the path http://localhost:1000/static/bug-rsbuild/..., but it loads everything from http://localhost:1000/..., resulting in an error.

But when use Webpack, work great: Image Image

When use rspack: Image Image

Reproduce link

https://github.com/cairon666/rsbuild-webpack-public-path-bug

Reproduce Steps

  1. donwload nginx
  2. load nginx.conf config
  3. start nginx
  4. npm i
  5. npm run dev
  6. go to localhost:1000
  7. click the buttons
inottn commented 1 week ago

This might be related to the default value of output.publicPath being auto in webpack. You can try setting output.publicPath to the same value and then see if the results are consistent.

cairon666 commented 1 week ago

It seems that the issue was resolved by adding output.publicPath: "auto". Thank you!