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

基于Nx的React微前端Webpack Module Federation报fn不是函数错误

Nx React微前端启动报错:TypeError: fn is not a function

我使用Nx工具创建了React微前端应用,启动时触发错误:TypeError: fn is not a function,该错误在加载来自8640的./Module时出现。

我的Webpack配置如下:

const { ModuleFederationPlugin } = require('webpack').container;
const nrwlConfig = require('@nrwl/react/plugins/webpack.js');

module.exports = (config, context) => {
  nrwlConfig(config);
  return {
    ...config,

    plugins: [
      ...config.plugins,
      new ModuleFederationPlugin({
        name: 'cart',
        filename: 'remoteEntry.js',
        exposes: {
          './Module': './src/remote-entry.ts',
        },
      }),
    ],
  };
};

我已查阅Webpack官方文档相关说明,但未能找到可行解决方案。

复现步骤

  • 获取对应代码仓库代码
  • 执行命令 npm install
  • 执行命令 npm run start
  • 打开 http://localhost:4200/cart 并开启开发者控制台

需要检查的文件:apps\cart\webpack.config.js


内容的提问来源于stack exchange,提问作者webDev_434

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 01:03:03