-
-
Notifications
You must be signed in to change notification settings - Fork 370
Description
Describe the bug
We’re working on a project using Preact + Rslib + Rsbuild in a monorepo setup. Once we began implementing Module Federation (@module-federation/rsbuild-plugin), we ran into an annoying issue related to the MF plugin.
Even when running the official example from https://github.com/web-infra-dev/rslib/tree/main/examples/module-federation
, we keep facing problems.
The first one is exactly what’s described here: https://module-federation.io/guide/troubleshooting/type/type-001
.
Even after running the suggested fix in the terminal and following the guide, the problem still persists.
So, we tried a different approach:
Disabled the dts option from the MF plugin.
Used the type declarations bundled by Rslib, combined with a third-party zip package to handle the types.
This workaround seems to work partially, but when we lazy-load a component from the federated library in the Rsbuild host, the types are missing, so we have to manually cast them when imported.
We also discovered that:
"@module-federation/rsbuild-plugin": "0.15.0" works (hotfix scenario)
"@module-federation/rsbuild-plugin": "0.21.2" fails to work properly
Steps to reproduce:
Run the project following the instructions in https://github.com/web-infra-dev/rslib/tree/main/examples/module-federation
Observe the console messages.
Attempt to fix according to the console advice.
(Optional workaround)
Disable the dts option in pluginModuleFederation inside the mf-react-component project.
Enable the dts option provided by Rslib.
Zip the @mf-types folder using a third-party package (e.g., zip-lib).
Enable remote types in the Rsbuild host project to consume them.
Check lazy imports on the Rsbuild host — the types won’t work properly.
Expected behavior:
Federated modules should expose valid type definitions when consumed via lazy imports in the Rsbuild host project.
Actual behavior:
When lazy-loading federated components, the host cannot resolve types properly, requiring manual casting of imported modules.
Environment:
Windows 11 pro
@module-federation/rsbuild-plugin: 0.21.2 (fails) / 0.15.0 (works)
rslib: latest
rsbuild: latest
Framework: Preact
Environment: Monorepo setup
Additional context:
Disabling dts generation in MF plugin and relying on Rslib’s declaration bundling allows the project to build successfully, but breaks type inference when lazy-loading modules through MF.
Reproduction
https://github.com/web-infra-dev/rslib/tree/main/examples/module-federation
Used Package Manager
pnpm
System Info
System:
OS: Windows 11 x64 (10.0.22631)
CPU: Intel Core i7 (Surface Laptop 4)
Memory: 16 GB RAM
Shell: PowerShell 7.4.4
Binaries:
Node: 22.x
pnpm: 9.x
npm: 10.x
Packages (mf-host):
react: 19.2.0
react-dom: 19.2.0
typescript: 5.9.3
@module-federation/rsbuild-plugin: 0.21.2
@rsbuild/core: 1.6.2
@rsbuild/plugin-react: 1.4.1
@types/react: 19.2.2
@types/react-dom: 19.2.2
Packages (mf-react-component):
react: 19.2.0
react-dom: 19.2.0
typescript: 5.9.3
@module-federation/enhanced: 0.21.2
@module-federation/rsbuild-plugin: 0.21.2
@module-federation/storybook-addon: 4.0.34
@rsbuild/plugin-react: 1.4.1
@rslib/core: link:../../../packages/core
storybook: 9.1.16
storybook-react-rsbuild: 2.1.3
storybook-addon-rslib: 2.1.3
http-server: 14.1.1
@types/react: 19.2.2
Monorepo:
Tool: pnpm workspaces
Structure: examples/module-federation (mf-host, mf-react-component)
Rslib: linked from packages/core
Environment:
Build tool: Rsbuild 1.6.2
Federation plugin: @module-federation/rsbuild-plugin 0.21.2
Framework: Preact/React 19
Mode: Monorepo (local linked Rslib)Validations
- Read the docs.
- Read the common issues list.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Module federation issue and not a framework-specific issue.
- The provided reproduction is a minimal reproducible example of the bug.