1

I attempted millions of things already, so help me please.


By following this documentation: https://nx.dev/recipes/module-federation/faster-builds#production-build-and-deployment-with-nx-cloud

I want to simulate same exercise, create a host and 3 remotes, and deploy the 4 applications on my LOCAL IIS, each one of the apps with a different port. (like if all of them would be in a different CND and deployed independently)


A) I created a MF site with a few characteristics:

  1. host (local port:4201, prod port:6001)
  2. remote shop (local port:4202, prod port:6002)
  3. remote cart (local port:4203, prod port:6003)
  4. remote about(local port:4204, prod port:6004)

B) To simulate PROD, I created on my Local IIS, all the webapps with the mentioned PROD ports, like

  • host:6001
  • shop:6002
  • cart:6003
  • about:6004

C) I configured as per the documentation, the following in the config prod (note same port for all):

module. Exports = withModuleFederation({
  ...moduleFederationConfig,
  remotes: [
    ['shop', 'http://localhost:6001/shop'],
    ['cart', 'http://localhost:6001/cart'],
    ['about', 'http://localhost:6001/about'],
  ],
});

which will be incorrect, the console will throw error like "localhost:6001/shop/remoteEntry.mjs net::ERR_ABORTED 404"

This has sense to me, because the port+folder doesn't exists, so is not correct to search the remoteEntry on that URL. I assume the example meant to have all the remotes under the same site, which beaks the purpose of MF to be deployed in different sites. In other words, the documentation is not correct for this example.

Based on the error, I modified the config to be like this:

module. Exports = withModuleFederation({
  ...moduleFederationConfig,
  remotes: [
    ['shop', 'http://localhost:6002'],
    ['cart', 'http://localhost:6003'],
    ['about', 'http://localhost:6004'],
  ],
});

This has more sense now, the 404 error while fetching "RemoteEntry.mjs" disappeared, so it means it is able to fetch the MJS files.

D) Now, trying to navigate

  • localhost:6001 = OK
  • localhost:6001/shop = ERR 404
  • localhost:6001/cart = ERR 404
  • localhost:6001/about = ERR 404

and now I don't know what else I should configure, it is supposed that the MF configuration would understand the ROUTE /shop, and search for the proper URL which will be in the port :6002, but instead i'm constantly receiving a 404.

Am I having a wrong understanding about module federation? Is it going to support all the remote sites to be deployed under diferent sites? How can I achieve this if so?

Thanks in advance.

Yogurtu
  • 2,656
  • 3
  • 23
  • 23

0 Answers0