From 0c3518c8597ed075751467c3f6d7ca69fc127fd1 Mon Sep 17 00:00:00 2001 From: ahabhgk Date: Wed, 7 Jan 2026 19:31:43 +0800 Subject: [PATCH 1/6] chore!: mark mf runtime tools as optional dependency --- packages/rspack/package.json | 5 ++++- .../src/container/ModuleFederationPlugin.ts | 18 +++++++++++++++--- pnpm-lock.yaml | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/rspack/package.json b/packages/rspack/package.json index 2df9e39b04e4..1cab325b5670 100644 --- a/packages/rspack/package.json +++ b/packages/rspack/package.json @@ -65,14 +65,17 @@ "webpack-sources": "3.3.3" }, "dependencies": { - "@module-federation/runtime-tools": "0.22.0", "@rspack/binding": "workspace:*", "@rspack/lite-tapable": "1.1.0" }, "peerDependencies": { + "@module-federation/runtime-tools": ">=0.22.0", "@swc/helpers": ">=0.5.1" }, "peerDependenciesMeta": { + "@module-federation/runtime-tools": { + "optional": true + }, "@swc/helpers": { "optional": true } diff --git a/packages/rspack/src/container/ModuleFederationPlugin.ts b/packages/rspack/src/container/ModuleFederationPlugin.ts index 5ae5b0662ffc..046e94c48c9e 100644 --- a/packages/rspack/src/container/ModuleFederationPlugin.ts +++ b/packages/rspack/src/container/ModuleFederationPlugin.ts @@ -292,9 +292,21 @@ function getPaths(options: ModuleFederationPluginOptions): RuntimePaths { }; } - const runtimeToolsPath = - options.implementation ?? - require.resolve('@module-federation/runtime-tools'); + let runtimeToolsPath: string; + if (options.implementation) { + runtimeToolsPath = options.implementation; + } else { + try { + runtimeToolsPath = require.resolve('@module-federation/runtime-tools'); + } catch (e) { + if ((e as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') { + throw new Error( + 'Module Federation runtime is not installed. Please install it by running:\n\n npm install @module-federation/runtime-tools\n', + ); + } + throw e; + } + } const bundlerRuntimePath = require.resolve( '@module-federation/webpack-bundler-runtime', { paths: [runtimeToolsPath] }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b1b40cbc2d1d..393c937552cd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -345,7 +345,7 @@ importers: packages/rspack: dependencies: '@module-federation/runtime-tools': - specifier: 0.22.0 + specifier: '>=0.22.0' version: 0.22.0 '@rspack/binding': specifier: workspace:* From a4e7eedb0c4f11248b13d88df69ff5525b5a0126 Mon Sep 17 00:00:00 2001 From: ahabhgk Date: Wed, 7 Jan 2026 19:40:28 +0800 Subject: [PATCH 2/6] doc --- .../docs/en/plugins/webpack/module-federation-plugin.mdx | 9 +++++++++ .../docs/zh/plugins/webpack/module-federation-plugin.mdx | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/website/docs/en/plugins/webpack/module-federation-plugin.mdx b/website/docs/en/plugins/webpack/module-federation-plugin.mdx index 33bd373f9132..31ead802906c 100644 --- a/website/docs/en/plugins/webpack/module-federation-plugin.mdx +++ b/website/docs/en/plugins/webpack/module-federation-plugin.mdx @@ -4,6 +4,15 @@ import { Stability, ApiMeta } from '@components/ApiMeta'; This plugin implements [Module Federation 1.5](https://github.com/module-federation/universe/tree/main/packages/enhanced). +:::tip +This plugin requires `@module-federation/runtime-tools` as a peer dependency. Please install it manually: + +```bash +npm install @module-federation/runtime-tools +``` + +::: + ## Example ```js title="rspack.config.mjs" diff --git a/website/docs/zh/plugins/webpack/module-federation-plugin.mdx b/website/docs/zh/plugins/webpack/module-federation-plugin.mdx index 3bb022150e98..725de047cec9 100644 --- a/website/docs/zh/plugins/webpack/module-federation-plugin.mdx +++ b/website/docs/zh/plugins/webpack/module-federation-plugin.mdx @@ -4,6 +4,15 @@ import { Stability, ApiMeta } from '@components/ApiMeta'; 该插件实现了 [Module Federation 1.5](https://github.com/module-federation/universe/tree/main/packages/enhanced)。 +:::tip +该插件需要 `@module-federation/runtime-tools` 作为 peer dependency,请手动安装: + +```bash +npm install @module-federation/runtime-tools +``` + +::: + ## 示例 ```js title="rspack.config.mjs" From 4530734a4064762a13eac667cf9d8585ea0e1eec Mon Sep 17 00:00:00 2001 From: ahabhgk Date: Wed, 7 Jan 2026 19:43:10 +0800 Subject: [PATCH 3/6] doc --- website/docs/en/plugins/webpack/module-federation-plugin.mdx | 3 +-- website/docs/zh/plugins/webpack/module-federation-plugin.mdx | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/website/docs/en/plugins/webpack/module-federation-plugin.mdx b/website/docs/en/plugins/webpack/module-federation-plugin.mdx index 31ead802906c..28f389d00907 100644 --- a/website/docs/en/plugins/webpack/module-federation-plugin.mdx +++ b/website/docs/en/plugins/webpack/module-federation-plugin.mdx @@ -5,12 +5,11 @@ import { Stability, ApiMeta } from '@components/ApiMeta'; This plugin implements [Module Federation 1.5](https://github.com/module-federation/universe/tree/main/packages/enhanced). :::tip -This plugin requires `@module-federation/runtime-tools` as a peer dependency. Please install it manually: +This plugin requires `@module-federation/runtime-tools`. Please install it manually: ```bash npm install @module-federation/runtime-tools ``` - ::: ## Example diff --git a/website/docs/zh/plugins/webpack/module-federation-plugin.mdx b/website/docs/zh/plugins/webpack/module-federation-plugin.mdx index 725de047cec9..6d1bd3fab9a5 100644 --- a/website/docs/zh/plugins/webpack/module-federation-plugin.mdx +++ b/website/docs/zh/plugins/webpack/module-federation-plugin.mdx @@ -5,12 +5,11 @@ import { Stability, ApiMeta } from '@components/ApiMeta'; 该插件实现了 [Module Federation 1.5](https://github.com/module-federation/universe/tree/main/packages/enhanced)。 :::tip -该插件需要 `@module-federation/runtime-tools` 作为 peer dependency,请手动安装: +该插件需要依赖 `@module-federation/runtime-tools`,请手动安装: ```bash npm install @module-federation/runtime-tools ``` - ::: ## 示例 From 4b68b9c2e590800e33e65383823c1fd11145739f Mon Sep 17 00:00:00 2001 From: ahabhgk Date: Wed, 7 Jan 2026 19:46:00 +0800 Subject: [PATCH 4/6] lint --- website/docs/en/plugins/webpack/module-federation-plugin.mdx | 1 + website/docs/zh/plugins/webpack/module-federation-plugin.mdx | 1 + 2 files changed, 2 insertions(+) diff --git a/website/docs/en/plugins/webpack/module-federation-plugin.mdx b/website/docs/en/plugins/webpack/module-federation-plugin.mdx index 28f389d00907..6f0efa590541 100644 --- a/website/docs/en/plugins/webpack/module-federation-plugin.mdx +++ b/website/docs/en/plugins/webpack/module-federation-plugin.mdx @@ -10,6 +10,7 @@ This plugin requires `@module-federation/runtime-tools`. Please install it manua ```bash npm install @module-federation/runtime-tools ``` + ::: ## Example diff --git a/website/docs/zh/plugins/webpack/module-federation-plugin.mdx b/website/docs/zh/plugins/webpack/module-federation-plugin.mdx index 6d1bd3fab9a5..e142e78cb811 100644 --- a/website/docs/zh/plugins/webpack/module-federation-plugin.mdx +++ b/website/docs/zh/plugins/webpack/module-federation-plugin.mdx @@ -10,6 +10,7 @@ import { Stability, ApiMeta } from '@components/ApiMeta'; ```bash npm install @module-federation/runtime-tools ``` + ::: ## 示例 From a469c914072a0693432f292808712a3ff418a49f Mon Sep 17 00:00:00 2001 From: ahabhgk Date: Thu, 8 Jan 2026 12:12:22 +0800 Subject: [PATCH 5/6] fix --- .../rspack/src/container/ModuleFederationPlugin.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/rspack/src/container/ModuleFederationPlugin.ts b/packages/rspack/src/container/ModuleFederationPlugin.ts index 046e94c48c9e..0f0cb5bf0363 100644 --- a/packages/rspack/src/container/ModuleFederationPlugin.ts +++ b/packages/rspack/src/container/ModuleFederationPlugin.ts @@ -36,7 +36,7 @@ export class ModuleFederationPlugin { apply(compiler: Compiler) { const { webpack } = compiler; - const paths = getPaths(this._options); + const paths = getPaths(this._options, compiler); compiler.options.resolve.alias = { '@module-federation/runtime-tools': paths.runtimeTools, '@module-federation/runtime': paths.runtime, @@ -283,7 +283,10 @@ function getRuntimePlugins(options: ModuleFederationPluginOptions) { return options.runtimePlugins ?? []; } -function getPaths(options: ModuleFederationPluginOptions): RuntimePaths { +function getPaths( + options: ModuleFederationPluginOptions, + compiler: Compiler, +): RuntimePaths { if (IS_BROWSER) { return { runtimeTools: '@module-federation/runtime-tools', @@ -297,7 +300,9 @@ function getPaths(options: ModuleFederationPluginOptions): RuntimePaths { runtimeToolsPath = options.implementation; } else { try { - runtimeToolsPath = require.resolve('@module-federation/runtime-tools'); + runtimeToolsPath = require.resolve('@module-federation/runtime-tools', { + paths: [compiler.context], + }); } catch (e) { if ((e as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') { throw new Error( From c1c9f33e0c7593ebdf2aa6a0ac409e752ec5219b Mon Sep 17 00:00:00 2001 From: ahabhgk Date: Thu, 8 Jan 2026 12:55:45 +0800 Subject: [PATCH 6/6] fix --- pnpm-lock.yaml | 3 +++ tests/rspack-test/package.json | 43 +++++++++++++++++----------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 393c937552cd..79c24b8dd62d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -714,6 +714,9 @@ importers: '@babel/preset-react': specifier: ^7.28.5 version: 7.28.5(@babel/core@7.28.5) + '@module-federation/runtime-tools': + specifier: ^0.22.0 + version: 0.22.0 '@rspack/binding-testing': specifier: workspace:* version: link:../../crates/rspack_binding_builder_testing diff --git a/tests/rspack-test/package.json b/tests/rspack-test/package.json index 0eb43a100395..380cad0224d5 100644 --- a/tests/rspack-test/package.json +++ b/tests/rspack-test/package.json @@ -13,9 +13,12 @@ "test:hot": "cross-env RSPACK_HOT_TEST=true node --no-warnings --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/@rstest/core/bin/rstest --config ./rstest.config.hot.ts --passWithNoTests" }, "devDependencies": { + "@babel/core": "^7.28.5", + "@babel/preset-react": "^7.28.5", + "@module-federation/runtime-tools": "^0.22.0", + "@rspack/binding-testing": "workspace:*", "@rspack/cli": "workspace:*", "@rspack/core": "workspace:*", - "@rspack/binding-testing": "workspace:*", "@rspack/plugin-preact-refresh": "1.1.4", "@rspack/plugin-react-refresh": "^1.5.3", "@rspack/test-tools": "workspace:*", @@ -32,54 +35,52 @@ "acorn": "^8.15.0", "babel-loader": "^10.0.0", "babel-plugin-import": "^1.13.8", + "bundle-loader": "^0.5.6", "chalk": "^4.1.2", + "coffee-loader": "^1.0.1", + "coffeescript": "^2.7.0", "core-js": "3.47.0", "css-loader": "^7.1.2", + "date-fns": "^4.1.0", + "es5-ext": "^0.10.64", + "exports-loader": "^5.0.0", "file-loader": "^6.2.0", + "fork-ts-checker-webpack-plugin": "^9.1.0", "graceful-fs": "^4.2.11", - "json-loader": "^0.5.7", "html-loader": "^5.1.0", "html-webpack-plugin": "^5.6.5", + "is-ci": "4.1.0", + "json-loader": "^0.5.7", + "json5": "^2.2.3", + "less": "4.4.2", "less-loader": "^12.3.0", "lodash": "^4.17.21", + "lodash-es": "^4.17.22", "memfs": "4.51.1", + "mime-types": "^3.0.2", "mini-svg-data-uri": "^1.4.4", "node-polyfill-webpack-plugin": "^4.1.0", "postcss-loader": "^8.2.0", "postcss-pxtorem": "^6.1.0", + "prop-types": "^15.8.1", "raw-loader": "^4.0.2", "react": "^19.2.3", "react-dom": "^19.2.3", "react-refresh": "^0.18.0", + "rimraf": "^5.0.10", "sass-loader": "^16.0.6", "source-map": "^0.7.6", "source-map-loader": "^5.0.0", "style-loader": "^4.0.0", "terser": "5.44.1", + "terser-webpack-plugin": "^5.3.16", "toml": "^3.0.0", + "ts-loader": "^9.5.4", "typescript": "^5.9.3", + "url-loader": "^4.1.1", "wast-loader": "^1.14.1", "webpack-sources": "3.3.3", "worker-rspack-loader": "^3.1.2", - "exports-loader": "^5.0.0", - "@babel/preset-react": "^7.28.5", - "coffee-loader": "^1.0.1", - "coffeescript": "^2.7.0", - "es5-ext": "^0.10.64", - "is-ci": "4.1.0", - "less": "4.4.2", - "lodash-es": "^4.17.22", - "mime-types": "^3.0.2", - "bundle-loader": "^0.5.6", - "rimraf": "^5.0.10", - "url-loader": "^4.1.1", - "terser-webpack-plugin": "^5.3.16", - "ts-loader": "^9.5.4", - "@babel/core": "^7.28.5", - "date-fns": "^4.1.0", - "fork-ts-checker-webpack-plugin": "^9.1.0", - "json5": "^2.2.3", - "prop-types": "^15.8.1", "xxhashjs": "^0.2.2", "yamljs": "^0.3.0" }