question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
ranshamaycommented, Nov 8, 2022

the plugin is designed to work on next@12 and next@11 there is a work @ScriptedAlchemy is doing to adjust it to next@13

#357 is the pr which will probably support it

@ScriptedAlchemy do you have any suggestions rather than wait?

1reaction
ScriptedAlchemycommented, Nov 9, 2022

I’ll patch over next 13 support, but the app directory will take more time to solve

Read more comments on GitHub >

github_iconTop Results From Across the Web

Next 13 rsc app by ScriptedAlchemy · Pull Request #357
Contribute to module-federation/nextjs-mf development by creating an account on GitHub. ... next dev produces "Failed to compile" error on Next.js13 with ...
Read more >
next.js - Module Federation or Micro Frontend is not working in ...
When we build repo cm-insurance-web using command npm run build, we can see javascript file is being created inside src/node/.next/static/chunks ...
Read more >
When I run Next.js 13 with turbopack I get "TypeError - Reddit
When I run Next.js 13 with turbopack I get "TypeError: Class extends value #" but no error with webpack. I have an app...
Read more >
@module-federation/nextjs-mf - npm
Implementing the Plugin. Use NextFederationPlugin in your next.config.js of the app that you wish to expose modules from. We'll ...
Read more >
Building React App with Module Federation and NextJS/React
This document's how-to will show you the failing issues I encountered and how I solve them; I hope it will help others when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found