Skip to content

nextjs mf does not generate remoteEntry.js #3845

Not planned
@tryptamine25

Description

@tryptamine25

I was using nextjs as a host application, but it got so bad - any changes require a reboot of the dev server, during the build on the server memory consumption went from 2gb to 10gb, that I decided to try to use nextjs application as a remote application.
Here is my next.config.js:

/** @type {import('next').NextConfig} */
const NextFederationPlugin = require('@module-federation/nextjs-mf');

const nextConfig = ({
  reactStrictMode: false,
  swcMinify: true,
  basePath: '/new',
  env: {
    NEXT_PUBLIC_FRONTOFFICE_OPENAPI_URL: process.env.NEXT_PUBLIC_FRONTOFFICE_OPENAPI_URL,
    NEXT_PUBLIC_FRONTOFFICE_CLIENT_API_URL: process.env.NEXT_PUBLIC_FRONTOFFICE_CLIENT_API_URL,
    EDO_LIGHT_API_URL: process.env.EDO_LIGHT_API_URL
  },
  module: {
    parser: {
      javascript: {
        dynamicImportMode: "eager"
      }
    }
  },
  webpack: (config) => {
    config.plugins.push(
      new NextFederationPlugin({
        name: "FrontOffice",
        filename: 'static/chunks/remoteEntry.js',
        exposes: {
          "./FrontOffice": "./pages/_app",
        },
        remotes: {
          "Stepper": `Stepper@${process.env.STEPPER_HOST}/remoteEntry.js`,
          "Payments": `FrontOfficePayments@${process.env.PAYMENTS_HOST}/remoteEntry.js`,
        },
      })
    );
    return config;
  },
  async redirects() {
    return [
      {
        source: '/profile',
        destination: '/profile/customer',
        permanent: false,
      },
      {
        source: '/',
        destination: '/profile',
        permanent: false,
        has: [
          {
            type: 'cookie',
            key: 'auth.accessToken',
          }
        ]
      },
      {
        source: '/profile/payments/payroll',
        destination: '/profile/payments',
        permanent: false,
      },
      {
        source: '/profile/payments/direct-payments',
        destination: '/profile/payments',
        permanent: false,
      },
    ];
  }
});

module.exports = nextConfig;

And at http://localhost:3000/new/static/chunks/remoteEntry.js
Or http://localhost:3000/static/chunks/remoteEntry.js I get a 404 error

"next": "12.2.5",
"@module-federation/nextjs-mf": "^7.0.8",
"webpack": "^5.89.0"

Activity

ScriptedAlchemy

ScriptedAlchemy commented on May 3, 2024

@ScriptedAlchemy
Member

use nextjs-mf v8

I recommend against next with module federation under any circumstance

tryptamine25

tryptamine25 commented on May 4, 2024

@tryptamine25
Author

@ScriptedAlchemy I tried the latest version of nextmf and I get the error - "No ModuleFederationPlugin(s) found.
Error: Cannot find module '/Users/alex/Documents/work/frontofficereact/node_modules/next/dist/compiled/lib/util/makeSerializable'"

tryptamine25

tryptamine25 commented on May 4, 2024

@tryptamine25
Author

@ScriptedAlchemy i read this - module-federation/core#1961 , but im work on macos

tryptamine25

tryptamine25 commented on May 4, 2024

@tryptamine25
Author

upgrading next version for 13.5.6 - not solved problem

ScriptedAlchemy

ScriptedAlchemy commented on May 6, 2024

@ScriptedAlchemy
Member
tryptamine25

tryptamine25 commented on May 6, 2024

@tryptamine25
Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @ScriptedAlchemy@tryptamine25

        Issue actions

          nextjs mf does not generate remoteEntry.js · Issue #3845 · module-federation/module-federation-examples