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

Module federation dev server static remote copy logic is incorrect. #21392

Closed
1 of 4 tasks
statop opened this issue Jan 29, 2024 · 8 comments · Fixed by #21709
Closed
1 of 4 tasks

Module federation dev server static remote copy logic is incorrect. #21392

statop opened this issue Jan 29, 2024 · 8 comments · Fixed by #21709
Assignees

Comments

@statop
Copy link

statop commented Jan 29, 2024

Current Behavior

If I only have 1 static remote, the federation dev server serves a different directory structure than if I had more than one.

Expected Behavior

If I only have 1 static remote, the federation dev server serves a the same directory structure than if I had more than one.

GitHub Repo

No response

Steps to Reproduce

  1. Serve a single static remote that does not have the project name as the name of the output folder.

Nx Report

>  NX   Report complete - copy this into the issue template

   Node   : 18.17.1
   OS     : darwin-arm64
   pnpm   : 8.14.3

   nx                 : 17.2.8
   @nx/js             : 17.2.8
   @nx/jest           : 17.2.8
   @nx/eslint         : 17.2.8
   @nx/workspace      : 17.2.8
   @nx/angular        : 17.2.8
   @nx/devkit         : 17.2.8
   @nx/eslint-plugin  : 17.2.8
   @nx/node           : 17.2.8
   @nx/plugin         : 17.2.8
   @nx/react          : 17.2.8
   @nx/rollup         : 17.2.8
   @nx/storybook      : 17.2.8
   @nx/vite           : 17.2.8
   @nx/web            : 17.2.8
   @nx/webpack        : 17.2.8
   typescript         : 5.2.2
   ---------------------------------------
   Community plugins:
   @openadp/tools-plugin : 24.5.0
   @storybook/angular    : 7.6.10
   ---------------------------------------
   Local workspace plugins:
   	 @openadp/tools-plugin

Failure Logs

No response

Package Manager Version

pnpm 8.14.3

Operating System

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

Additional Information

The problematic code is here - https://github.com/nrwl/nx/blob/master/packages/react/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts#L58

It assumes that all projects output to a folder with the project name. Many projects use a path that matches the path to the project sources.

@Coly010 Coly010 self-assigned this Jan 30, 2024
@Coly010 Coly010 added blocked: more info needed scope: module federation Issues related to module federation support labels Jan 30, 2024
@Coly010
Copy link
Contributor

Coly010 commented Jan 30, 2024

Hi @statop !

Can you provide an example even just as a comment here of when this occurs and why this is a bug?

We only need to move projects into a common location when there is more than 1 static remote. To allow a single http-server to serve all the remotes that are required.

When module-federation-dev-server is used, it will point the remotes location to the correct place.
This only happens during local dev.

Production builds will still use the correct location defined in module-federation.config or any overrides provided in webpack.config.prod.

@statop
Copy link
Author

statop commented Jan 30, 2024

The code here
https://github.com/nrwl/nx/blob/master/packages/react/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts#L58
assumes that the parent directory name is the same as the name of the project.

That is not always the case.

@statop
Copy link
Author

statop commented Jan 30, 2024

In other words, if the output path for my project, which is named foo-bar, is dist/foo/bar, then the server will serve up the foo directory and try to load resources from a non-existant foo-bar directory

@Coly010
Copy link
Contributor

Coly010 commented Jan 30, 2024

This should be solved by this line, no?

I know now how to test this at least

@statop
Copy link
Author

statop commented Jan 30, 2024

in the case of more than one static remote, yes.

The problem is when there is only one static remote.

@statop
Copy link
Author

statop commented Feb 13, 2024

@Coly010 there is still a problem when the output directory does not contain the whole project name

@Coly010 Coly010 reopened this Feb 13, 2024
@Coly010
Copy link
Contributor

Coly010 commented Feb 14, 2024

@statop I cannot reproduce that behaviour on the latest version of Nx. If you can provide a reproduction repo, I'll happily reopen this and take a look.

@Coly010 Coly010 closed this as completed Feb 14, 2024
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants