-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Labels
Description
Describe the bug
When using Vite's Environment API with an SSR environment that has server.hmr: false, Vite should not create a WebSocket server (similar to how server.ws: false works). However, Vite still creates a WebSocket server and attempts to bind to the default port 24678, causing EADDRINUSE errors in monorepos where multiple Vite instances run simultaneously.
This is particularly problematic for:
- Nuxt 4.2.x (uses environment API and sets
hmr: falsefor SSR builds) - Monorepos running multiple Vite dev servers with environment API
- Any SSR framework using environment-specific HMR configuration
Reproduction
https://github.com/leo91000/vite-hmr-port-24678-bug/tree/main
Steps to reproduce
- Clone the reproduction repo
- Run
pnpm install - Run
pnpm dev(starts 2 apps using environment API withhmr: falsein parallel) - Observe the error:
apps/app1 dev: App1 running on http://localhost:3001
apps/app2 dev: WebSocket server error: Port 24678 is already in use
apps/app2 dev: App2 running on http://localhost:3002
System Info
System:
OS: Linux 6.17 EndeavourOS
CPU: (32) x64 Intel(R) Core(TM) i9-14900K
Memory: 76.89 GB / 94.05 GB
Container: Yes
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.19.0 - /home/leoc/.local/share/mise/installs/node/22.19.0/bin/node
Yarn: 1.22.22 - /home/leoc/.local/share/mise/installs/node/22.19.0/bin/yarn
npm: 10.9.3 - /home/leoc/.local/share/mise/installs/node/22.19.0/bin/npm
pnpm: 10.20.0 - /home/leoc/.local/share/mise/installs/node/22.19.0/bin/pnpm
bun: 1.3.1 - /home/leoc/.bun/bin/bun
Deno: 2.3.3 - /home/leoc/.deno/bin/deno
Browsers:
Firefox: 144.0
Firefox Developer Edition: 144.0Used Package Manager
pnpm
Logs
apps/app1 dev: App1 running on http://localhost:3001
apps/app2 dev: WebSocket server error: Port 24678 is already in use
apps/app2 dev: App2 running on http://localhost:3002
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- 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.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Kiansa, naka87003 and G-Cyrille