pretext icon indicating copy to clipboard operation
pretext copied to clipboard

`bun start` fails on Windows due to `lsof` not being available

Open max0n4ik opened this issue 8 months ago • 2 comments

Environment

  • OS: Windows
  • Bun version: 1.3.11

Steps to reproduce

bun start

Expected behavior

Dev server starts on http://127.0.0.1:3000.

Actual behavior

bun: command not found: lsof
error: Failed to start server. Is port 0 in use?
 syscall: "listen",
   errno: 0,
    code: "EADDRINUSE"

Root cause

The start script (and start:lan, start:watch) uses lsof to free the port before starting the server:

pids=$(lsof -tiTCP:$PORT -sTCP:LISTEN 2>/dev/null)

lsof is a Unix/macOS-only utility and does not exist on Windows. Because the command fails, the PORT variable never gets assigned, so --host=$HOST:$PORT passes an empty port. Bun falls back to port 0, which it cannot bind, resulting in EADDRINUSE.

Suggested fix

Replace the lsof-based port-freeing logic with a cross-platform alternative — either a small Bun/Node script, or simply remove it and let Bun handle the port conflict with a clear error message:

"start": "bun pages/*.html pages/demos/*.html pages/demos/*/index.html --host=127.0.0.1:3000"

max0n4ik avatar Apr 02 '26 19:04 max0n4ik

Fixed in #100.

I moved the Unix-only dev-server startup logic out of package.json into a small script, so the entrypoint is no longer tied to lsof plus shell-specific behavior.

This should fix the Windows failure path while keeping start, start:lan, and start:watch the same from the outside.

beeegee avatar Apr 05 '26 04:04 beeegee

Thanks! superceeded by b86579e

chenglou avatar Apr 05 '26 17:04 chenglou