You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been trying to run the experimental module federation support in this plugin without writing a custom server file because I feel I may break something as it will be a large scale project and want to rely on the full capabilities of the framework and the plugin. Configuring a React Router project to use this rsbuild plugin was smooth, but, I used the federation example in this repo and tried to first configure a remote app and faced issues.
So, if I create a build and then start the build with the following configuration:
I'm just few days into bundlers, so I may be wrong somewhere silly, but, here what I have observed is, I've console.log the build app.js exports, created by the plugin, that react-router-serve receives in the remote-1/node_modules/@react-router/serve/dist/cli.js, and it is receiving functions with promises, but the actual resolved values are expected. So I wrote an adaptor server file which will import all the bundle exports and export them after executing the functions and it worked.
// Import for local referenceimport*asoriginalBuildfrom'./build/server/static/js/app.js';console.log('Original build:',originalBuild);// Resolve all promise-returning functions from app.jsconstresolveExports=async()=>{// Each of these functions returns a Promise that resolves to the actual valueconstassetsValue=awaitoriginalBuild.assets();constassetsBuildDirectoryValue=awaitoriginalBuild.assetsBuildDirectory();constbasenameValue=awaitoriginalBuild.basename();constentryValue=awaitoriginalBuild.entry();constfutureValue=awaitoriginalBuild.future();constisSpaValue=awaitoriginalBuild.isSpaMode();constprerenderValue=awaitoriginalBuild.prerender();constpublicPathValue=awaitoriginalBuild.publicPath();constroutesValue=awaitoriginalBuild.routes();constssrValue=awaitoriginalBuild.ssr();console.log('Resolved exports successfully');return{assets: assetsValue,assetsBuildDirectory: assetsBuildDirectoryValue,basename: basenameValue,entry: entryValue,future: futureValue,isSpaMode: isSpaValue,prerender: prerenderValue,publicPath: publicPathValue,routes: routesValue,ssr: ssrValue};};// Resolve and export all valuesconstresolvedExports=awaitresolveExports();// Export individual values (not re-exporting from app.js)exportconstassets=resolvedExports.assets;exportconstassetsBuildDirectory=resolvedExports.assetsBuildDirectory;exportconstbasename=resolvedExports.basename;exportconstentry=resolvedExports.entry;exportconstfuture=resolvedExports.future;exportconstisSpaMode=resolvedExports.isSpaMode;exportconstprerender=resolvedExports.prerender;exportconstpublicPath=resolvedExports.publicPath;exportconstroutes=resolvedExports.routes;exportconstssr=resolvedExports.ssr;// Log for debuggingconsole.log('Original build:',originalBuild);console.log('Resolved exports:',resolvedExports);
All good till here, but the issue is with npm run dev command. I get the same above error with rsbuild dev command because now I think it internally generates dev build and serves it through HMR. I cannot get it working without writing a custom server and then use tsx dev-server.ts command like how similarly it is done in federation example.
Will it be possible to not use a custom server script and run federation?
The text was updated successfully, but these errors were encountered:
neetigyachahar
changed the title
Setting up module federation in React Router using rsbuild without a custom server script
Setting up module federation in React Router (framework mode) using rsbuild without a custom server script
Apr 23, 2025
I have been trying to run the experimental module federation support in this plugin without writing a custom server file because I feel I may break something as it will be a large scale project and want to rely on the full capabilities of the framework and the plugin. Configuring a React Router project to use this rsbuild plugin was smooth, but, I used the federation example in this repo and tried to first configure a remote app and faced issues.
So, if I create a build and then start the build with the following configuration:
I get the below error:
I'm just few days into bundlers, so I may be wrong somewhere silly, but, here what I have observed is, I've console.log the build
app.js
exports, created by the plugin, thatreact-router-serve
receives in theremote-1/node_modules/@react-router/serve/dist/cli.js
, and it is receiving functions with promises, but the actual resolved values are expected. So I wrote an adaptor server file which will import all the bundle exports and export them after executing the functions and it worked.All good till here, but the issue is with
npm run dev
command. I get the same above error withrsbuild dev
command because now I think it internally generates dev build and serves it through HMR. I cannot get it working without writing a custom server and then usetsx dev-server.ts
command like how similarly it is done in federation example.Will it be possible to not use a custom server script and run federation?
I have pushed the code here for reference: https://github.com/neetigyachahar/react-router-rsbuild-module-federation-demo
Thank you for the efforts.
The text was updated successfully, but these errors were encountered: