You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem is within this function, the mod variable will always return undefined. This is because the path within the update is relative to the project root, so if your project is within /home/me/my-project and you had a file named main.js within that directory, the update's path property would be /main.js.
The fsPath is an absolute path to the file, prepended by /@fs/, which is different from the format given in the Update object, meaning that the mod variable will always be undefined, causing it to do an early return.
Describe the bug
Any
import.meta.hot.accept
function will break HMR and the function passed to accept is never called.I've figured out the cause of this bug by modifying the module in
node_modules
and adding some console logs, here is what I've found.vitest/packages/vite-node/src/hmr/hmr.ts
Lines 105 to 114 in b7ce195
The problem is within this function, the
mod
variable will always return undefined. This is because thepath
within the update is relative to the project root, so if your project is within/home/me/my-project
and you had a file namedmain.js
within that directory, the update'spath
property would be/main.js
.However, the
hotModulesMap
's keys are added here:vitest/packages/vite-node/src/hmr/hmr.ts
Line 248 in b7ce195
The
ownerPath
parameter is given in the runner:vitest/packages/vite-node/src/client.ts
Line 375 in b7ce195
The
fsPath
is an absolute path to the file, prepended by/@fs/
, which is different from the format given in theUpdate
object, meaning that themod
variable will always be undefined, causing it to do an early return.Reproduction
https://github.com/lukadev-0/vite-node-hmr-bug
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: