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

An error has occurred in Angular: No routes were found that match the URL segment 'null'

I've recently developed a simple Angular page that extracts an ID (a guid) from the URL and uses it to make an API call. While I have successfully implemented similar pages in the past without any issues, this particular one is presenting challenges w ...

Steps to modify the CSS of a custom component in Angular 8

I have been attempting to override the css of a custom component selector, however, my attempts have been unsuccessful. I have tried using ":ng-deep" but it hasn't worked. How can I go about finding a solution for this issue? app.component.html: < ...

After deploying my next.js app on cPanel, it suddenly displays a blank screen

I recently deployed my Next.js app on cPanel and encountered a blank screen issue, although it works perfectly fine when tested locally. Here's the detailed process I followed: 1. To begin with, I created a custom server.js file in the root directory ...

The reCAPTCHA feature in Next.js form is returning an undefined window error, possibly due to an issue with

Trying to incorporate reCAPTCHA using react-hook-form along with react-hook-recaptcha is posing some challenges as an error related to 'window' being undefined keeps popping up: ReferenceError: window is not defined > 33 | const { recaptchaL ...

What are some effective ways to exclude multiple spec files in playwright?

Within my configuration, I have three distinct projects. One project is responsible for running tests for a specific account type using one login, while another project runs tests for a different login. Recently, I added a third project that needs to run t ...

Utilizing the .env.local file. Encountering the issue of process.env.NEXT_PUBLIC_VERCEL_ENV being undefined on the

I am currently utilizing Next.js in combination with Vercel. Here is the contents of my .env.local file: # Generated by Vercel CLI VERCEL="1" VERCEL_ENV="development" VERCEL_URL="" VERCEL_GIT_PROVIDER="" VERCEL_GIT_R ...

What is causing unexpected behavior when one service calls another service?

Let's say I make a call to a service that returns an observable, and if it doesn't encounter any errors, then another service should be called which also returns an observable. What I tried doing is calling both services separately, one after th ...

Encountering Nested CSS bugs while implementing Tailwind in a Next.js/React project

Just diving into the world of Next.js/React. I recently went through the Tailwind CSS for Next.js tutorial and successfully integrated Tailwind into my project by following these steps: npm install -D tailwindcss postcss autoprefixer npx tailwindcss init - ...

Encountered an error during module parsing: An unexpected character '@' was found at position 1 in the code related to vuejs, vuetify, and vu

Encountering an issue when trying to add/integrate Vuetify, such as importing it with the line 'import Vuetify from 'vuetify/lib' Vue.use(Vuetify)' in main.js Error: ERROR in ./node_modules/vuetify/src/stylus/components/_grid.styl Mod ...

Implementing an API route to access a file located within the app directory in Next.js

Struggling with Nextjs has been a challenge for me. Even the most basic tasks seem to elude me. One specific issue I encountered is with an API call that should return 'Logged in' if 'Me' is entered, and display a message from mydata.tx ...

Is TypeScript failing to enforce generic constraints?

There is an interface defined as: export default interface Cacheable { } and then another one that extends it: import Cacheable from "./cacheable.js"; export default interface Coin extends Cacheable{ id: string; // bitcoin symbol: stri ...

What are some React component libraries compatible with Next.js 13.1?

I'm exploring Next.js and experimenting with version 13.1 and the new app directory. Is it feasible to accomplish this without sacrificing the advantages of server controls? An error message I encountered states: You're attempting to import a c ...

Troubleshooting the issue of having multiple menu items in Material UI

Every time I attempt to add the Menu component multiple times, I encounter an issue with the popup list displaying incorrectly. To demonstrate this problem, you can view it through the link provided on codesandbox below. I have included data-id attributes ...

Is it possible that using npm link could be the root cause of the "module not

As I delve into understanding how to utilize TypeScript modules in plain JavaScript projects, it appears that I am facing a limitation when it comes to using npm linked modules. Specifically, I can successfully use a module that is npm-linked, such as &apo ...

Navigating through nested JSON Objects for dropdown functionality in Angular 6 - a step-by-step guide

Currently, I am facing a challenge in Angular 6.0 where I am trying to use HttpClient to iterate through JSON data retrieved from a local file within my assets folder. Below is the sample JSON Data: [{ "configKey": [{ "user1": [{ ...

Use the `fetch` method in JavaScript/TypeScript to make an API call to an IPFS URI but be prepared for potential issues like CORS restrictions, network errors, or

I am currently working on a Next.js project with TypeScript in the browser, and I need to execute the following fetch request: const tokenURIResponse = await fetch( "ipfs://bafybeig37ioir76s7mg5oobetncojcm3c3hxasyd4rvid4jqhy4gkaheg ...

Tips for sending data returned asynchronously from an Observable in Angular from a Child component to its Parent

I am facing a challenge passing Async data from child to parent component. When I try to access console.log(this.values) within the ngAfterViewInit() method in the parent component's HTML page load, it returns an empty value. However, upon clicking th ...

How to reference an object from an external file in TypeScript using Ionic 2 and Angular 2

I am currently developing a mobile application with Ionic2 and have integrated a simple online payment service called Paystack for processing payments. The way it operates is by adding a js file to your webpage and then invoking a function. <script> ...

Encountered an error while running npm run dev on a NextJS application due to an

Upon running the npm run dev command, the next app is displaying an error message: $→mmoLD;%g?wŷ↓▬ovH0a5*ؒl͛Siy☺rO7%L]%∟hk ^ SyntaxError: Invalid or unexpected token at wrapSafe (internal/modules/cjs/loader.js:988:16) at Module._comp ...

What measures can I take to protect this API?

In the process of developing a full-stack application using Next-JS with an API connected to Firebase, my main concern revolves around ensuring the security of this API. Specifically, I am looking for ways to protect a variable called "Premium" stored in F ...