Skip to content

next dev produces "Failed to compile" error on Next.js13 with NextFederationPlugin #368

@aphiwadchh

Description

@aphiwadchh

Hi, thanks so much for building such an amazing library.

I'm running into issue using NextFederationPlugin with Next.js13. I follow the implementation from here https://github.com/module-federation/nextjs-mf/tree/main/packages/nextjs-mf
and when try running pnpm dev my local site produce error :

Failed to compile
webpack/runtime/readFile chunk loading
Cannot convert undefined or null to object

image

I have push my setup here https://github.com/aphiwadchh/next13-mf-test

What I did:

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

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  webpack(config, options) {
      config.plugins.push(
        new NextFederationPlugin({
          name: 'nextremote',
          filename: 'static/chunks/remoteEntry.js',
          exposes: {
            './HelloWorld': './pages/hello-world',
          },
          shared: {},
        })
      );

    return config;
  },
}

module.exports = nextConfig

With above config, I can see .next/static/chunks/remoteEntry.js is generated, but the site crash with error.

What I tried:

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

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  webpack(config, options) {
    const { isServer } = options;

    // wrapping !isServer here since my need is for SSG only
    if (!isServer) {
      config.plugins.push(
        new NextFederationPlugin({
          name: 'nextremote',
          filename: 'static/chunks/remoteEntry.js',
          exposes: {
            './HelloWorld': './pages/hello-world',
          },
          shared: {},
        })
      );
    }

    return config;
  },
}

module.exports = nextConfig

With above setup, I be able to run pnpm dev and works, however the file .next/static/chunks/remoteEntry.js is not being generated. So I have to run pnpm build. This sort of works, however it slow down development time cuz I can't have hot-reload update.

Have anyone run into similar issue? How do you fix/work-around this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions