You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My use case is for dynamically loaded remotes based on a manifest. At runtime the host app fetches information about where to load remotes from and uses @module-federation/enhanced/runtime's registerRemotes to register them.
This approach works well except for the fact that with the built app this causes shared dependencies like react to be loaded from the remote, rather than the host. I'd like all remotes to be consuming host's shared dependencies so in future I am able to bump versions and only release host, rather than all applications. The same behaviour does not happen when running the app in dev mode, but keeping everything else the same nx serve host (note: in my example you also need to tweak the mf-manifest.json location to http://localhost:4201/mf-manifest.json in apps/host/src/main.ts).
Note: separate discussion here as to whether this approach is suitable at all: #30275
See here how the react dependency is sourced from 'shop' rather than the expected 'host'.
And the subsequent fetch from the shop directory:
I'm able to reproduce this behaviour with a few lines of changes from a generated module federation example.
Expected Behavior
Shared dependencies should come from host in dev and the production build. It's unclear to me why there should be a difference.
Move the built dist/apps/shop inside dist/apps/host
cd dist/apps/host
Serve the host directory e.g. python -m http.server 8000
Navigate to the served site in your browser, e.g. http://localhost:8000
Look at the devtools network logs, filter for JS requests, and observe the URL of each file. You should see that dependencies like react are coming from the /shop/ directory, rather than the expected root localhost:8000
Alternatively, enter __FEDERATION__ in the dev tools console and open up the react dependency in SHARE, observe that it has the field from as 'shop', rather than 'host'
Current Behavior
My use case is for dynamically loaded remotes based on a manifest. At runtime the host app fetches information about where to load remotes from and uses
@module-federation/enhanced/runtime
'sregisterRemotes
to register them.This approach works well except for the fact that with the built app this causes shared dependencies like react to be loaded from the remote, rather than the host. I'd like all remotes to be consuming host's shared dependencies so in future I am able to bump versions and only release host, rather than all applications. The same behaviour does not happen when running the app in dev mode, but keeping everything else the same
nx serve host
(note: in my example you also need to tweak the mf-manifest.json location tohttp://localhost:4201/mf-manifest.json
inapps/host/src/main.ts
).Note: separate discussion here as to whether this approach is suitable at all: #30275
See here how the react dependency is sourced from 'shop' rather than the expected 'host'.

And the subsequent fetch from the shop directory:

I'm able to reproduce this behaviour with a few lines of changes from a generated module federation example.
Expected Behavior
Shared dependencies should come from host in dev and the production build. It's unclear to me why there should be a difference.
GitHub Repo
https://github.com/oscar8880/nx-module-federation-issues/tree/deps-in-child-issue
Steps to Reproduce
deps-in-child-issue
npm install
nx build host
dist/apps/shop
insidedist/apps/host
cd dist/apps/host
python -m http.server 8000
http://localhost:8000
__FEDERATION__
in the dev tools console and open up the react dependency in SHARE, observe that it has the field from as 'shop', rather than 'host'To create the example I followed the docs here https://nx.dev/concepts/module-federation/faster-builds-with-module-federation. I'm using nx
20.4.6
, nodev20.10.0
, npm10.2.3
.npx create-nx-workspace nx-module-federation-issues --preset=apps
nx add @nx/react
nx g @nx/react:host apps/host --remotes=shop
Nx Report
Failure Logs
Package Manager Version
No response
Operating System
Additional Information
No response
The text was updated successfully, but these errors were encountered: