Skip to content
Latchkey

Playwright "http://localhost:3000 is already used" webServer error in CI

With reuseExistingServer: false, Playwright wants to own the port but finds something already listening, so it stops. In CI this usually means a leftover server from a previous step, or another shard starting its own server on the same port.

What this error means

Startup fails with "Error: http://localhost:3000 is already used, make sure that nothing is running on the port/url specified by reuseExistingServer is not set to true".

playwright
Error: http://localhost:3000 is already used, make sure that nothing is running
on the port/url or set reuseExistingServer:true in config.webServer.

Common causes

A leftover server still holding the port

An earlier step started the app and did not shut it down, so the port is occupied when Playwright tries to launch its own.

Multiple shards starting servers on one port

Each sharded job starts its own webServer on the same fixed port, so the second collides with the first on a shared host.

How to fix it

Reuse an already-running server intentionally

If something is meant to be running, set reuseExistingServer so Playwright attaches instead of starting a duplicate.

playwright.config.ts
webServer: {
  command: 'npm run start',
  url: 'http://localhost:3000',
  reuseExistingServer: true,
},

Give each job an isolated port

Drive the port from an env var so shards and parallel jobs do not collide.

playwright.config.ts
url: `http://localhost:${process.env.PORT || 3000}`,

How to prevent it

  • Stop background servers from earlier steps before Playwright starts.
  • Use distinct ports per shard or parallel job.
  • Set reuseExistingServer deliberately rather than leaving it default.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →