You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Next.js集成Rsbuild Module Federation时远程组件资源请求源错误的问题求助

Next.js集成Rsbuild Module Federation时远程组件资源请求源错误的问题求助

我遇到了一个类似的Module Federation问题,但之前的解决方案对我不管用😔。和那个问题的区别是,我的远程组件是通过@module-federation/rsbuild-plugin来暴露的。

Host端配置(next.config.ts)

const { NextFederationPlugin } = require('@module-federation/nextjs-mf');

module.exports = {
  webpack(config, options) {
    config.output.publicPath = 'auto'
    if (!options.isServer) {
        config.plugins.push(
        new NextFederationPlugin({
          name: 'host',
          filename: 'static/chunks/remoteEntry.js',
          remotes: {
            remote: 'remote@http://localhost:3001/remote.js',
          },
        }),
      );
    }

    return config;
  },
};

Remote端配置(rsbuild.config.ts)

import { pluginModuleFederation } from '@module-federation/rsbuild-plugin'
import { defineConfig } from '@rsbuild/core'
import { pluginReact } from '@rsbuild/plugin-react'

export default defineConfig({
  plugins: [
    pluginReact(),
    pluginModuleFederation({
      name: 'remote',
      library: { type: 'var', name: 'remote' },
      filename: 'remote.js',
      exposes: {
        './Button': './src/Button.tsx',
      },
      shared: {
        react: {
          singleton: true,
          version: '0',
          requiredVersion: false,
        },
        'react-dom': {
          requiredVersion: false,
          singleton: true,
          version: '0',
        },
      },
    }),
  ],
  server: {
    port: 3001,
  }
})

现在出现的问题是,远程组件的chunk请求会从Host的源发起,导致404错误:

GET http://localhost:3000/static/js/async/__federation_expose_Button.e9dde250.js net::ERR_ABORTED 404 (Not Found)

有没有大佬能给点思路呀?谢谢啦🙏

备注:内容来源于stack exchange,提问作者user1847403

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 13:14:50