diff --git a/packages/vite/src/node/server/hmr.ts b/packages/vite/src/node/server/hmr.ts index c7849d8c78c49d..da9222cf4b139e 100644 --- a/packages/vite/src/node/server/hmr.ts +++ b/packages/vite/src/node/server/hmr.ts @@ -181,6 +181,9 @@ export async function handleFileAddUnlink( const relative = path.relative(base, file) if (match(relative, pattern)) { modules.push(module) + // We use `onFileChange` to invalidate `module.file` so that subsequent `ssrLoadModule()` + // calls get fresh glob import results with(out) the newly added(/removed) `file`. + server.moduleGraph.onFileChange(module.file!) } } }