Diagnosing Vite.js Hot Module Replacement (HMR) Failures in Development
Step‑by‑step guide to diagnose why Vite.js Hot Module Replacement is not updating your browser during development.
16 Sept 2026, 01:05 UTC

Recognizable Condition
When editing a source file while the Vite dev server is running, you notice one of the following:
- Changes appear only after a full page reload.
- The browser console shows no
[vite] HMR connectedmessage. - The Network tab does not list a persistent WebSocket connection to
/hot.
Cause & Diagnostic Table
| Observed Symptom | Possible Cause |
|---|---|
| No HMR log, WebSocket missing | HMR disabled via server.hmr: false |
| HMR log present but updates ignored for specific file types (e.g., .jsx, .vue, .scss) | Missing or outdated framework/plugin for those extensions |
| HMR works initially, then stops after adding a custom proxy or middleware | Middleware rewriting or proxying the /hot WebSocket URL |
Running vite build instead of vite | Build command does not start the dev server or HMR |
| HMR fails after upgrading Vite | Plugin version mismatch with the new Vite version |
Ordered Checks
- Verify dev server mode
Run the command that starts the development server:
# In your project root viteEnsure you are not invoking
vite buildorvite preview. - Check console for HMR connection
Open the browser’s developer tools console and look for:
[vite] HMR connectedIf absent, proceed to the next check.
- Inspect the WebSocket
In the Network tab, filter by
WSand verify a connection tohttp://localhost:{port}/hotremains open. - Review Vite configuration
Open
vite.config.js(or .ts) and confirm:export default defineConfig({ server: { // HMR should be true or omitted hmr: true } });If you see
hmr: false, change it totrueor remove the property. - Validate framework plugins
Determine which file types you are editing and ensure the matching plugin is installed and compatible:
- React:
@vitejs/plugin-react - Vue 3:
@vitejs/plugin-vue - Svelte:
@sveltejs/vite-plugin-svelte - SCSS/SASS:
sass(no extra plugin needed) orvite-plugin-scssif using custom processing.
Check versions against your Vite version (e.g.,
npm list vite @vitejs/plugin-react). - React:
- Audit custom middleware/proxy
If you have a
server.middlewareor a proxy (e.g., viahttp-proxy-middlewareor Vite’sserver.proxy), ensure they do not interfere with the/hotpath. A safe pattern is to exclude it:server: { proxy: { '/api': { target: 'http://localhost:3000', changeOrigin: true }, // do not proxy /hot '^/hot': false } }
Fixes Tied to Findings
HMR disabled in config
Set server.hmr to true or remove the line, then restart the dev server.
Missing/outdated plugin
Install the correct plugin at a version matching your Vite release:
# Example for React with Vite 5
npm i -D @vitejs/plugin-react@^4.0.0
After installation, restart the dev server.
Middleware/proxy interfering
Adjust the proxy rule to exclude /hot or move the middleware after Vite’s internal handlers. Restart the server and verify the WebSocket reconnects.
Using build command
Switch to vite (or vite dev) for development. Reserve vite build for production builds only.
Plugin version mismatch after Vite upgrade
Upgrade the plugin to the latest compatible version, or consult the plugin’s changelog for breaking changes. Then restart the dev server.
Escalation Criteria
If after performing all checks and applying the corresponding fix:
- The HMR WebSocket still does not connect,
- Console shows errors like
Failed to construct 'WebSocket'ornet::ERR_CONNECTION_REFUSED, - Changes continue to require a full reload despite correct configuration,
consider the following steps:
- Check for conflicting processes on the same port (e.g., another dev server) using
lsof -i :{port}ornetstat -tlnp. - Temporarily disable all custom middleware and plugins to isolate the issue; re‑enable them one by one.
- Consult the Vite
--debugflag for verbose logging:vite --debug. - If the problem persists, file an issue on the Vite repository or the specific plugin’s repository, providing the verbose log, your
vite.config.js, and package versions.
Limitations and Practical Verification
Even with a correct setup, HMR will not trigger for:
- Files ignored by Vite’s module graph (e.g., assets imported with a query that Vite treats as raw).
- Server‑only code that never reaches the client (Vite will not attempt HMR on Node‑only modules).
To verify that HMR is functioning for a typical client‑side file:
- Open a component file (e.g.,
src/App.jsx) in your editor. - Make a visible change, such as altering text inside a
<h1>tag. - Save the file and observe the browser: the text should update instantly without a full page reload.
- Open the console and confirm you see a log like
[vite] HMR updatefollowed by the module name.
If the update appears instantly and the log is present, HMR is working as expected.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.