-
Notifications
You must be signed in to change notification settings - Fork 102
Description
Describe the bug
Hello,
I have an issue where HMR does not work for a shared file: dependency.
I have a minimal reproduction with two Vite apps using @module-federation/vite:
apps/host-appapps/remote-app
Both apps depend on two local dependencies via file: dependencies:
pkgs/shared-pkgpkgs/not-shared-pkg
The difference is that shared-pkg is declared in the Module Federation shared config in both apps, while not-shared-pkg is not.
In dev mode, HMR behaves differently depending on which local dependency changes:
- Changing
pkgs/not-shared-pkg/index.jsworks as expected and the UI updates through HMR. - Changing
pkgs/shared-pkg/index.jsdoes not update the UI through HMR.
This makes it look like HMR is broken specifically for local dependencies that are shared through Module Federation.
Reproduction
- Clone https://github.com/clemvnt/vite-mf-shared-package-hmr-issue.
- Install dependencies in both apps.
- Start
apps/remote-appwithnpm run dev. - Start
apps/host-appwithnpm run dev. - Open both apps in the browser.
- Edit
pkgs/not-shared-pkg/index.jsand change the exported value from"A"to"B". - Observe that both apps update correctly.
- Edit
pkgs/shared-pkg/index.jsand change the exported value from"A"to"B". - Observe that the apps do not update correctly through HMR.
Actual behavior
Changes in the non-shared local dependency are reflected immediately, but changes in the shared local dependency are not.
Expected behavior
When a shared local dependency changes, both apps should receive the update in dev mode, the same way they do for a local dependency that is not shared.
Note
I suspect the issue may be related to shared dependencies being included in optimizeDeps.
Validations
- Read the docs.
- Read the common issues list.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- The provided reproduction is a minimal reproducible example of the bug.