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
If your vite.config.js configures a publicDir, but the specified directory does not exist, the build works fine and the dev server starts fine as well.
However as soon as a file is edited, the file system watcher from chokidar does not detect any changes.
It may depend a bit on the layout of the project, I attached a vite.new link to a similar setup in which i ran into the problem.
The problem can simply be solved but not configuring the publicDir explicitly or creating the specified folder.
Maybe a bit obscure scenario, but it did take me a bit to find out, why HMR was not working 😅 It was not a hard fix but I would have expected something to either error or log rather than silently breaking HMR.
A possible solution to this in Vite could maybe be to only watch the publicDir in case it exists (or contains any files)?
What works for me at least seems to be making the following change:
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
Describe the bug
If your vite.config.js configures a
publicDir
, but the specified directory does not exist, the build works fine and the dev server starts fine as well.However as soon as a file is edited, the file system watcher from
chokidar
does not detect any changes.It may depend a bit on the layout of the project, I attached a
vite.new
link to a similar setup in which i ran into the problem.The problem can simply be solved but not configuring the
publicDir
explicitly or creating the specified folder.Maybe a bit obscure scenario, but it did take me a bit to find out, why HMR was not working 😅 It was not a hard fix but I would have expected something to either error or log rather than silently breaking HMR.
A possible solution to this in Vite could maybe be to only watch the
publicDir
in case it exists (or contains any files)?What works for me at least seems to be making the following change:
to here:
vite/packages/vite/src/node/server/index.ts
Line 495 in be2c3fa
Reproduction
https://stackblitz.com/edit/vitejs-vite-l1sytzhy?file=src%2Fmain%2Ffrontend%2Fsrc%2Fcounter.js
Steps to reproduce
vite.config.js
which configures thepublicDir
to thesrc/main/frontend/public
src/main/frontend
should exist, but directorysrc/main/frontend/public
should not existindex.html
that includes a script in pathsrc/main/frontend/src/main.js
vite --debug hmr
main.js
with not result in a log output that any file was changes, nor will the browser preview be updatedpublicDir
or removing this configuration will fix itSystem Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: