Skip to content
Notes🇫🇷 Lire en français

Vite: enable polling under WSL for hot reload

When a project lives on a Windows drive mounted in WSL (/mnt/c/...), Vite hot reload never triggers: you edit a file, nothing changes in the browser.

Cause

WSL2 uses the 9P protocol to access Windows files through /mnt/c. inotify events do not cross this layer. The Vite watcher (chokidar) relies on them and never sees the modifications.

Fix

Enable polling in the Vite config. With Astro, that goes in astro.config.mjs:

export default defineConfig({
  vite: {
    server: {
      watch: {
        usePolling: true,
      },
    },
  },
});

Hot reload works again, at the cost of some extra CPU: the watcher scans files at regular intervals instead of listening for kernel events.

Alternative

Move the project into the native WSL filesystem (~/projects/... instead of /mnt/c/...). inotify events then work normally, without polling. But if your editor runs on the Windows side, file access goes through \\wsl$, which has its own limitations.

References