nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
22.66k stars 2.26k forks source link

Dev remotes appears to only work with the last alphabetized remote. #11615

Open bobsakson opened 1 year ago

bobsakson commented 1 year ago

Using the React sample https://github.com/nrwl/react-module-federation, if you run

nx serve host --open --devRemotes=shop

You can modify the greeting.tsx and see the HMR work and update the component.

If you run

nx serve host --open --devRemotes=about

The HMR does not reload and the changes are not reflected.

ryansevilla commented 1 year ago

I'm seeing the same issue. Would love a fix.

mikerhyssmith commented 1 year ago

I wondered if anyone could point me in the general direction of where a fix for this might live - this is quite critical for us so I'm more than happy to submit a fix !

Phat-RobinAI commented 1 year ago

A workaround for us at the moment would be to always include the last alphabetized remote in your list of devRemotes e.g nx serve host --open --devRemotes=[remote you want hmr],[last alphabetized module]

bigcakes commented 11 months ago

Any updates here? This is still an issue on latest NX from what I can tell.

jaysoo commented 10 months ago

After some investigation, it looks like the behavior is coming from webpack's ModuleFederationPlugin. Since workspace libraries are shared by default, it is loading from the last remote, which happens to be served statically.

We will continue to look into this issue, but in the meantime you can unshare some workspace libraries using the following:

// module-federation.config.js
module.exports = {
  shared: (libName, libConfigFromNx) => {
    return libName === '@react-module-federation/shared-components'
      ? false
      : libConfigFromNx
  },
  // ...
};

This will force the remote app to load its own version of the workspace library. Be careful though, if the library requires shared state (like redux) then this strategy will not work. You also need to define this config for each app, so it might be good to have a base config at the workspace root and reuse it.

github-actions[bot] commented 4 months ago

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

bigcakes commented 4 months ago

Not stale, still an issue