use StreamingTargetPlugin instead of @module-federation/enhanced when running MFE in SSR mode #30128
+2
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Current Behavior
@nrwl/nx-pipelines-reviewers This PR addresses issues encountered when using Module Federation with Server-Side Rendering (SSR) in new Micro Frontend (MFE) workspaces created following the Nx documentation (https://nx.dev/recipes/react/module-federation-with-ssr).
Currently, creating a new MFE workspace results in the following errors:
1) The error below occurs due to the server attempting to directly load modules using @module-federation/enhanced, which is designed for browser environments and cannot fetch remote modules on the server.
2) the error below arises when attempting to hardcode the remoteEntry.js file path in the ModuleFederationConfig, indicating a problem with how remote entries are handled in SSR.
This PR resolves these issues by utilizing the StreamingTargetPlugin from @module-federation/node within withModuleFederationForSSR. This approach enables remote module loading during SSR, ensuring proper loading on the server-side. Remote modules are now correctly loaded in SSR mode, without errors, though re-rendering still occurs on the client if you don't hydrate root.
Expected Behavior
When using Server-Side Rendering (SSR) with Module Federation, remote modules must be loaded by the server. Currently, this process fails, resulting in errors and a fallback to browser-side loading, which defeats the purpose of SSR. This PR corrects this behavior.