-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Dynamic module federation doesn't work with proposed remote app manifest file #21901
Comments
hi ... any resolution on this ? thanks |
Since we're using Short version of our workaround. It works for us since we know that localhost and a port number always relates to development. Deployment environments never use ports. // Host app bootstrap, e.g. `bootstrap.ts`
const staticRemotesPort = project.targets.serve.options.staticRemotesPort;
// We actually fetch this dynamically to utilize cache busting, e.g. `remoteEntry.{build-hash}.mjs`
const remoteEntryName = 'remoteEntry.mjs';
// Fetch environment config to get remote urls
fetch('environment.config.json').then((config) => {
setRemoteUrlResolver((remote) =>
urlResolver(
remote,
config.moduleFederationManifest[remote],
remoteEntryName,
staticRemotesPort
)
);
...
bootstrapApplication(AppComponent, { providers: [ ... ] });
})
.catch( ... ); export const urlResolver = async (
remoteName: string,
remoteUrl: string,
remoteEntryName: string,
staticRemotesPort: number
): Promise<string> => {
const url = `${remoteUrl}/${remoteEntryName}`;
const devUrlRegex = /^(.*localhost:)(\d{4})$/;
// Check whether remote url is from `serve` command or not
if (!remoteUrl.match(devUrlRegex)) {
return url;
}
// Check remote url
return fetch(url)
.then(() => {
return url;
})
.catch(() => {
console.warn(
'[urlResolver] dev remote not running, assume a static remote'
);
// Map to static port and path
// E.g. http://localhost:4201 --> http://localhost:4242/app-remote
const staticRemoteUrl = `${remoteUrl.replace(
devUrlRegex,
`$${1}${staticRemotesPort}`
)}/${remoteName}`;
return `${staticRemoteUrl}/${remoteEntryName}`;
});
}; |
Also have this issue, preventing us from upgrading to 17.2. |
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. |
Current Behavior
There has been a change to how static remotes are served when only a single http-server host all remotes, though each remote has its own port number. So
4200
relates to the host app and4201
to all static remotes.More port numbers are only used when we start serving one or more remotes in dev mode. Then we could have
4200
still for the host app but4201
serves remote1 in dev mode and4202
serves the static remotes.For me using dynamic module federation the remote manifest file
module-federation.manifest.json
isn't as predictable as I'm used to anymore.When I serve my host app with static remotes the remote entry files can not be found since all remotes are served from a single port, requiring additional app folder in the path.
I recently updated from 16 to 18.
Expected Behavior
Serving host app with either static or dev remotes should be able to work with a predictable manifest file.
GitHub Repo
No response
Steps to Reproduce
Generate host and remotes from example code
https://nx.dev/recipes/module-federation/create-a-host#scaffold-a-host-with-remotes
Generated
module-federation.manifest.json
This configuration works well for remotes in dev mode since they both are served on their individual ports
But when serving static remotes they both are served on
4201
fromdist/apps/mfe-dyn
, which doesn't work anymoreNone of the remotes are found. For this scenario the manifest must look like this:
So how should I configure my manifest file to be predictable and dynamic enough for both static and dev remotes?
Nx Report
Failure Logs
No response
Package Manager Version
No response
Operating System
Additional Information
No response
The text was updated successfully, but these errors were encountered: