Discovering the steps to showcase _app.tsx within next.js 13 through module federation

I am faced with a situation where I have two Next.js 13 projects: Homepage and Admin Panel. My goal is to showcase the entire Admin Panel (specifically _app.tsx) and embed it within Homepage. To achieve this, I have set up both projects utilizing @module-federation/nextjs-mf in their respective next.config.js files. However, upon attempting to import the app page from the Admin Panel into Homepage, an error occurs indicating that the element type is invalid. Below is the exact error message:

Unhandled Runtime Error Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. Check the render method of `MyApp`. 

This snippet displays my configuration for Admin Panel in next.config.js

  webpack: (config, options) => {
    const { isServer } = options;
    config.plugins.push(
      new NextFederationPlugin({
        name: "admin",
        remotes: {
          homepage: `homepage@http://localhost:3000/_next/static/${
            isServer ? "ssr" : "chunks"
          }/remoteEntry.js`,
        },
        exposes: {
          "./submitButton": "./component/UI/Buttons/SubmitButton/SubmitButton.tsx",
          "./app": "./pages/_app.tsx",
        },
        filename: "static/chunks/remoteEntry.js",
        extraOptions: {
          exposePages: true,
        },
      })
    );
    return config;
  }

In an attempt to showcase the complete Admin Panel project (_app.tsx) via module federation and integrate it within the Homepage project, I encountered the aforementioned error. I was hoping to seamlessly import the app page from the Admin Panel into the Homepage without facing any glitches. Yet, the error persisted.

Is it feasible to expose _app.tsx utilizing module federation? If yes, what could be triggering this error? If not, what are the potential alternatives?

Answer №1

If you want to reveal certain pages without specifying the file names, simply indicate the route itself and set exposePages to true. Give this a try, it worked for me in my nextjs project.

{
    exposes: {
      "./contactForm": "./component/UI/Forms/ContactForm/ContactForm.tsx",
      "./dashboard": "./pages/dashboard", //the main dashboard page
      "./profile": "./pages/profile" //the user profile page
    },
    extraOptions: {
        "exposePages": true
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to access URL parameters in the back-end using Node.js?

How can I extract querystring parameters email, job, and source from the following URL? I want to use these parameters in my service class: @Injectable() export class TesteService{ constructor(){} async fetchDataFromUrl(urlSite: URL){ ...

Is today within the current week? Utilizing Moment JS for time tracking

There is a problem that I am facing. Can you assist me in determining whether the day falls within the current week? I am currently developing a weather forecast service and need to validate if a given day is within the current week. The only clue I have ...

Generating an array of elements from a massive disorganized object

I am facing a challenge in TypeScript where I need to convert poorly formatted data from an API into an array of objects. The data is currently structured as one large object, which poses a problem. Here is a snippet of the data: Your data here... The go ...

Server-side authentication issue with AWS Cognito in NextJS using Amplify

I have implemented Cognito for authenticating my app. Everything works fine in the local environment when I run yarn dev, yarn build, and yarn start. However, in the Amplify server deployment, the SSR authentication is not functioning correctly as it alwa ...

Combining static assets in NextJs

When utilizing NextJS for server-side rendering of my ReactJS pages to improve SEO, I run into an issue after running `yarn next build`. The output shows: First Load JS shared by all 127 kB ├ chunks/2a8530436833c39e06d2 ...

Angular mat-table experiencing issues with matToolTip functionality

My Angular project is using Angular Material 16x, but for some reason, the matToolTip is not displaying at all. I have experimented with various versions, including a basic matTooltip="hello world", but I just can't seem to get it to work. I have come ...

Typescript HashMap implementation with Lists as values

Currently delving into TypeScript, I am attempting to generate a collection in a manner akin to the following Java example: HashMap<String, List<String>> hashMap = new HashMap<String,List<String>>(); Struggling to locate any releva ...

Eliminate the "Potential 'undefined' Object" error without resorting to non-null assertion or optional chaining

Below is the code snippet I am working with: export type ConditionalItemType = [ { condition: string }, { [key: string]: FormItemDataType } ]; export type ConditionalItemDataType = ConditionalItemType[]; export type FormItemDataType = { required: bo ...

What is the process for connecting custom transformers to a compiler host?

My custom TypeScript watcher is set up like this: const compilerHost = typescript.createWatchCompilerHost(config.fileNames, config.options, typescript.sys, undefined, reportDiagnostic) typescript.createWatchProgram(compilerHost) I am trying to integrate ...

Can we limit the return type of arrow function parameters in TypeScript?

Within my typescript code, there is a function that takes in two parameters: a configuration object and a function: function executeMaybe<Input, Output> ( config: { percent: number }, fn: (i: Input) => Output ): (i: Input) => Output | &apos ...

The type 'Readonly<Ref<Readonly<any>>>' does not have the property 'forEach' available

Having an issue with state management in Vue3 (Pinia) using the Composition API. I successfully retrieved an array called countryCodes and now I want to copy all items from this array into another array called countries defined in the state. However, whe ...

Troubleshooting import errors with Typescript for C3 and D3 libraries

I have recently started working on a project using the C3 graphing library within an Ionic2/Angular2 TypeScript setup. After installing C3 via npm and the type definitions via tsd, I imported it into my own TypeScript file like this: import {Component} fr ...

Vercel Serverless Function - The Node Canvas on Serverless Function has surpassed the 50mb maximum size restriction

I'm currently creating images on the server using user data that is sent to the API endpoint in my Next.js project, utilizing the canvas package. Everything is working smoothly, but I've run into an issue when trying to deploy the project on Ver ...

Typescript: The ConstructorParameters type does not support generics

Incorporating TypeScript 3.7, I created an interface featuring a property designed to accept a constructor function: interface IConstruct<T> { type: new (...args:ConstructorParameters<T>) => T; } I initially assumed that IConstruct<Us ...

What is the best way to incorporate a dynamic background in NextJS using Tailwind?

I have a poster image that I want to use as a background image, fetched from MovieDb. I tried putting it inside the className like this: className={bg-[url('${path}')] h-screen bg-cover bg-center text-white border-b-8 border-b-solid border-b-sla ...

The Quasar application does not eliminate console.log() statements during production builds

I've been facing difficulties in removing the console.log() from my Quasar app for production builds. Despite checking solutions on various platforms like StackOverflow, Quasar forums, and GitHub, I am still struggling to eliminate the console.log st ...

Having trouble debugging TypeScript files in Chrome following an Angular update

I have been experimenting with writing a basic app using Angular 4.2.5 to expand my knowledge. Previously, I was able to debug the TypeScript files in Chrome without any issues. However, after updating to Angular 5.2.7, I am no longer able to view the Type ...

TypeScript encounters challenges with implementing Redux containers

I'm struggling to understand the correct way to type Redux containers. Let's consider a simple presentational component that looks like this: interface MyProps { name: string; selected: boolean; onSelect: (name: string) => void; } clas ...

Vue/Vite vanilla setup encountering a 'Failed to fetch dynamically imported module' TypeError

We're currently working with a vanilla Vue/Vite setup and I'm encountering the error message TypeError: Failed to fetch dynamically imported module in Sentry logs. It appears that these errors coincide with new deployments to production, but I d ...

What is the best way to inject a custom Angular service into a test in TypeScript without needing to mock it?

I have defined my modules and tests as shown below, but I encounter an issue when attempting to inject ContentBlocksService into the beforeEach(mock.inject((ContentBlocksService)... statement. It shows an error message saying Unknown provider ContentBlocks ...