Skip to content

Environment API with server.hmr: false still creates WebSocket server causing port conflicts #21041

@leo91000

Description

@leo91000

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: false for 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

  1. Clone the reproduction repo
  2. Run pnpm install
  3. Run pnpm dev (starts 2 apps using environment API with hmr: false in parallel)
  4. 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.0

Used 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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions