Search code examples
reactjsnext.jswebpack-module-federation

`module-not-found` while expose a component with NextJs module federation


Keep getting - error Module not found: Can't resolve './components/Test' Here is what my next.config.js looks like

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

module.exports = {
  webpack(config, options) {
    if (!options.isServer) {
      config.plugins.push(
        new NextFederationPlugin({
          name: 'next-js',
          remotes: {},
          filename: 'static/chunks/remoteEntry.js',
          exposes: {
            './test': './components/Test',
          },
          shared: {
            react: {
              requiredVersion: false,
              singleton: true,
            },
          },
        }),
      );
    }
    return config;
  },
  // your original next.config.js export
  reactStrictMode: true,
};

Here is my file structure

src
  -- app
  -- components
       -- Test.tsx
next.config.js

Did I miss anything?

Tried to expose a component from next js with module federation.


Solution

  • Please use complete path of file with extension in expose object. Replace

    exposes: {
                './test': './components/Test',
              },
    

    with

    exposes: {
                './test': './components/Test.tsx',
              },