-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dependency accept callback does not work in watch mode #4950
Comments
This is a known issue, it will be fixed by vitejs/vite#12165 |
I saw that the other issue was merged and wanted to try it out. While it's still very early (vite 5.1 isn't published yet), things do seem to be working with that branch. Here's the setup for anyone else who finds this.
Some things to note about accepting...
I created a helper function for generalizing a function that's regenerated based on module updates.
And that can be plugged into something like Express...
I confirmed that the top file wasn't reloaded for dep changes and that deps and deps of deps could update and be seen in the result which was the behavior I was originally expecting. Given the work upstream, this whole package is probably obsolete, so I'll close the issue. |
Describe the bug
Vite's HMR API has a deps signature that lets a module observe the reload of a dependency without reloading itself.
This doesn't currently seem to work with
vite-node
.The repro example is a simple module that starts a http server and imports a value from a dependent. The base module has an accept callback for the dependency.
The expectation is that if the dep is modified, the parent module will not reload, but it's accept callback will run.
Instead, the behavior depends on a variety of factors.
Mode ts vs. js means running
vite-node -w basic.ts
vs. compiling to js first and runningvite-node -w basic.js
. Result is what happens whendep.ts
(or js) is changed.EADDRINUSE
[vite-node] hot updated: /src/dep.js via ...
, however the answer doesn't changeEADDRINUSE
EADDRINUSE
Running a server provides a way of seeing when the base module is reloading and shouldn't. In all cases, I was expecting to see the
hot updated
message and the answer to change, but the only case where the deps-based accept was recognized and the module didn't reload was js/Linux, and there the accept callback never runs.There seems to be a lot of sensitivity internally to how paths are registered with
hotModulesMap
in hmr.ts being used to relate paths in events coming back from the vite dev server based on the transformed source to the dep specifiers registered by the module's HMR API call. That is only partly working on Linux, and not at all on Windows.I noticed while debugging that Windows paths were getting particularly mangled. The issue seems to be in the base importAnalysis plugin where vite uses
path.posix
to normalize the url.vite-node
is passing in a path likeC:/project/file.ts
which gets turned into/project/C:/project/file.ts
. This can be avoided by passing a posix-absolute/C:/project/file.ts
to begin with, but there's a lot of identifier juggling going on in this code-base, and I don't understand it well enough to make a more specific recommendation.Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-ien7n8?file=src%2Fbasic.ts
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: