Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modules are unable to be loaded when using @nx/rspack:module-federation-dev-server #30138

Open
1 of 4 tasks
sceptre12 opened this issue Feb 22, 2025 · 0 comments
Open
1 of 4 tasks

Comments

@sceptre12
Copy link

Current Behavior

When I execute: pnpm nx run host_v1:serve and I open up the localhost link.
I get the following error:

Image

Expected Behavior

When I execute: pnpm nx run host_v1:serve and I open up the localhost link.
I expect to see the modules linked correctly and the webpage working.

GitHub Repo

https://github.com/sceptre12/nx_bug1

Steps to Reproduce

Execute the following:

  1. pnpx create-nx-workspace@latest --pm pnpm

  2. pnpm nx add @nx/react

  3. pnpm nx g @nx/react:host apps/shell_v1 --e2eTestRunner none --bundler rspack --style tailwind

  4. Open up the shell_v1 proejct.json file and select the project name and do a find and replace to ensure the name for the project is shell_v1

  5. pnpm nx g @nx/react:remote apps/remotes/header --e2eTestRunner none --bundler rspack --style tailwind --host shell_v1

  6. pnpm nx g @nx/react:remote apps/remotes/footer --e2eTestRunner none --bundler rspack --style tailwind --host shell_v1

  7. pnpm nx run shell_v1:serve --verbose --skip-nx-cache

Click on the link. On the webpage click on header or footer and you should see a similar error

Nx Report

NX   Report complete - copy this into the issue template

Node           : 22.13.0
OS             : darwin-arm64
Native Target  : aarch64-macos
pnpm           : 9.15.3

nx                     : 20.4.5
@nx/js                 : 20.4.5
@nx/jest               : 20.4.5
@nx/eslint             : 20.4.5
@nx/workspace          : 20.4.5
@nx/devkit             : 20.4.5
@nx/eslint-plugin      : 20.4.5
@nx/module-federation  : 20.4.5
@nx/playwright         : 20.4.5
@nx/react              : 20.4.5
@nx/rspack             : 20.4.5
@nx/web                : 20.4.5
typescript             : 5.7.3
---------------------------------------
Registered Plugins:
@nx/js/typescript
@nx/playwright/plugin
@nx/eslint/plugin
@nx/jest/plugin
---------------------------------------
Community plugins:
@koliveira15/nx-sonarqube : 4.2.1

Failure Logs

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

There is a work around for this issue.

It seems that if i update my host_v1 module-federation-config.ts file like below that fixes things..
What I also noticed is that when i perform a normal build with the app everything works.

When checking the difference I noticed that when i'm running the pnpm nx run host_v1:serve There is a runtime.js file loaded on the page..

During a normal rspack build everything is working as expected.
I'm wondering if the run time itself is not getting the proper paths to the urls from the other remote.

Before:

import { ModuleFederationConfig } from '@nx/module-federation'

const config: ModuleFederationConfig = {
    name: 'host_v1',
    /**
     * To use a remote that does not exist in your current Nx Workspace
     * You can use the tuple-syntax to define your remote
     *
     * remotes: [['my-external-remote', 'https://nx-angular-remote.netlify.app']]
     *
     * You _may_ need to add a `remotes.d.ts` file to your `src/` folder declaring the external remote for tsc, with the
     * following content:
     *
     * declare module 'my-external-remote';
     *
     */
    remotes: ['header_v1', 'footer_v1'],
}

/**
 * Nx requires a default export of the config to allow correct resolution of the module federation graph.
 **/
export default config

After:

import { ModuleFederationConfig } from '@nx/module-federation'

const config: ModuleFederationConfig = {
    name: 'host_v1',
    /**
     * To use a remote that does not exist in your current Nx Workspace
     * You can use the tuple-syntax to define your remote
     *
     * remotes: [['my-external-remote', 'https://nx-angular-remote.netlify.app']]
     *
     * You _may_ need to add a `remotes.d.ts` file to your `src/` folder declaring the external remote for tsc, with the
     * following content:
     *
     * declare module 'my-external-remote';
     *
     */
    exposes: {}, // THIS IS CHANGEEEEEE
    remotes: ['header_v1', 'footer_v1'],
}

/**
 * Nx requires a default export of the config to allow correct resolution of the module federation graph.
 **/
export default config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant