How to Fix “is already used” Error with Playwright webServer
When you run npx playwright test and the tests stop with an is already used error before any test starts, it means another server is already running on the URL (or port) set in webServer. For example, a dev server you started earlier may still be running in another terminal. If you stop that server, the error goes away without changing the configuration.
I reproduced the error in a test environment and included the exact message it printed. The article covers how to find and stop the running process, two ways to avoid stopping it (reuseExistingServer and changing the port), and a case where a similar-looking setup fails with a different error. For the basic webServer setup, see How to Start a Dev Server with Playwright webServer.
The test environment was Ubuntu 24.04, Node.js 22.23.5, @playwright/test 1.63.0 (Chromium 158.0.8127.36, headless), TypeScript 5.9.3, and lsof 4.95.0. For the server, I used a small one built with Node.js's http module that returns an HTML page with a single heading. For the "server running in another terminal," I started the same server in the background instead. I did not test Windows or macOS, development servers such as Vite, or HTTPS servers.
Reproducing the error
In the config file, I set webServer to run node server.mjs and wait for http://localhost:3000 to respond. reuseExistingServer was set to false.
// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
testDir: './tests',
reporter: 'list',
use: {
baseURL: 'http://localhost:3000',
browserName: 'chromium',
},
webServer: {
command: 'node server.mjs',
url: 'http://localhost:3000',
reuseExistingServer: false,
},
});
The test only opens the top page and checks the heading.
// tests/home.spec.ts
import { test, expect } from '@playwright/test';
test('トップページの見出しが出る', async ({ page }) => {
await page.goto('/');
await expect(page.getByRole('heading', { level: 1 })).toHaveText('猫の手カウンター');
});
I started the same server on port 3000 beforehand and then ran the tests. They stopped immediately with exit code 1.
$ npx playwright test
Error: http://localhost:3000 is already used, make sure that nothing is running on the port/url or set reuseExistingServer:true in config.webServer.
The message says: "http://localhost:3000 is already in use. Make sure nothing is running on that port or URL, or set reuseExistingServer:true in config.webServer." The message itself lists the possible fixes.
When I wrote port: 3000 instead of url, I got exactly the same message. Even with port, the message shows http://localhost:3000. Note that port is marked as deprecated in the official documentation, which recommends using url instead.
How Playwright decides the port is already in use
Setting the environment variable DEBUG=pw:webserver shows what Playwright does before it starts the server. (I omitted the date from the timestamps. In the commands below, I have also left out the env prefix that I added for the record.)
$ DEBUG=pw:webserver npx playwright test
03:32:41.780Z pw:webserver HTTP GET: http://localhost:3000/
03:32:41.788Z pw:webserver HTTP Status: 200
03:32:41.790Z pw:webserver WebServer is already available
03:32:41.790Z pw:webserver Terminating the WebServer
03:32:41.790Z pw:webserver Terminated the WebServer
Error: http://localhost:3000 is already used, make sure that nothing is running on the port/url or set reuseExistingServer:true in config.webServer.
…(後略)
Before starting command, Playwright sends one GET request to url. If it gets a response, it concludes the server is already running. When reuseExistingServer is false, it reports an error and does not start command. The TestConfig webServer description also says that when reuseExistingServer is false, it reports an error if a process is already listening on that port or url.
In the Playwright 1.63.0 source, when you specify url, it checks the HTTP response code. A response from 200 to 403 counts as "running." If / returns 404, it also checks /index.html. When you specify port, it only checks whether it can connect to that port on 127.0.0.1 or ::1.

Finding and stopping the process using the port
First, find out what is using the port. On Linux, you can use lsof. -iTCP:3000 -sTCP:LISTEN narrows the output to whatever is listening on TCP port 3000. -nP shows IP addresses and port numbers as numbers, without converting them to host names or service names. In the output, I replaced the value in the USER column with user.
$ lsof -nP -iTCP:3000 -sTCP:LISTEN
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 1603 user 21u IPv4 5461 0t0 TCP *:3000 (LISTEN)
You can see that a process with COMMAND
node and PID 1603 is listening. If it is a dev server you started and forgot about, stop it with kill using the PID. Adding -t to lsof prints only the PID, so you can pass it directly to kill.
$ kill $(lsof -t -iTCP:3000 -sTCP:LISTEN)
$ lsof -nP -iTCP:3000 -sTCP:LISTEN
After stopping it, lsof printed nothing and exited with code 1, which means nothing is listening anymore. When I ran the tests again with the same config file, the error was gone and the tests passed.
$ npx playwright test
Running 1 test using 1 worker
✓ 1 tests/home.spec.ts:3:5 › トップページの見出しが出る (97ms)
1 passed (673ms)
I ran the tests again right after, and they passed again. Afterward, lsof showed nothing listening on port 3000. The server Playwright started itself is stopped by Playwright when the tests finish, so it does not get in the way of the next run.
kill $(lsof -t …) stops whatever process is listening on that port, regardless of what it is. It might be a database or the server for another project. Before you run it, check the COMMAND and PID in the lsof output and make sure it is safe to stop.
Reusing the running server
Sometimes you want to keep a dev server running and run the tests against it many times. In that case, set reuseExistingServer to true. Playwright then does not start command and runs the tests against the server that is already running. The official webServer documentation suggests using !process.env.CI in most cases. This means: reuse the server when the environment variable CI is not set (locally), and start it fresh every time when it is set (in CI).
webServer: {
command: 'node server.mjs',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
},
With the server running on port 3000, the tests passed when I ran them without CI. With CI=1, they stopped with the same is already used error as before. Because the server is not reused when CI is set, if this error only appears in CI, check whether something is already running on that port before the tests start.
Keep in mind that when you reuse a server, Playwright does not check whether the process on that port is really the app you want to test. I ran a server that returned a different heading on port 3000 and ran the same config. Playwright started testing against that server and failed because the heading did not match (I omitted part of the output and replaced the path with /path/to/app).
$ npx playwright test
Running 1 test using 1 worker
✘ 1 tests/home.spec.ts:3:5 › トップページの見出しが出る (5.1s)
…(中略)
Error: expect(locator).toHaveText(expected) failed
Locator: getByRole('heading', { level: 1 })
Expected: "猫の手カウンター"
Received: "別のアプリ"
Timeout: 5000ms
…(中略)
at /path/to/app/tests/home.spec.ts:5:57
…(後略)
The error shows up as a test failure, so it is hard to tell that the port conflict is the cause. If you set reuseExistingServer to true and a test fails in a strange way, use lsof to check what is using that port.
Changing the port to run them separately
If you do not want to stop the running server or reuse it, change the port the test server uses. I read the port number from the environment variable PORT and used the same number in three places: command and url in webServer, and baseURL in use.
// playwright.config.ts
import { defineConfig } from '@playwright/test';
const port = Number(process.env.PORT ?? 3000);
export default defineConfig({
testDir: './tests',
reporter: 'list',
use: {
baseURL: `http://localhost:${port}`,
browserName: 'chromium',
},
webServer: {
command: `PORT=${port} node server.mjs`,
url: `http://localhost:${port}`,
reuseExistingServer: !process.env.CI,
},
});
With the server still running on port 3000, I ran the tests with CI=1. Since the port was still 3000, they stopped with is already used. When I also set PORT=3100, Playwright started the server on port 3100, and the tests passed.
$ CI=1 PORT=3100 npx playwright test
Running 1 test using 1 worker
✓ 1 tests/home.spec.ts:3:5 › トップページの見出しが出る (97ms)
1 passed (715ms)
If the number differs in even one of the three places, the port that is started, the URL that is waited on, and the URL the test opens will not match. Building all three from a single variable, as above, prevents that mismatch.
When you get "was not able to start" instead of "is already used"
Sometimes the port is in use but you do not get is already used. I ran a server on port 3000 that returned 404 for every URL, then ran the tests with the original config. I got a different error (I omitted part of the [WebServer] lines).
$ npx playwright test
[WebServer] node:events:497
[WebServer] throw er; // Unhandled 'error' event
[WebServer] ^
[WebServer]
[WebServer] Error: listen EADDRINUSE: address already in use 0.0.0.0:3000
…(中略)
[WebServer] Node.js v22.23.5
Error: Process from config.webServer was not able to start. Exit code: 1
With DEBUG=pw:webserver, I saw that both / and /index.html returned 404 in the first check. Playwright therefore decided the server was not running yet and started command. The node server.mjs it started exited with EADDRINUSE (address already in use) because port 3000 was taken, and Playwright reported that the server could not be started.
The cause is the same as with is already used: another process is holding that port. If you see the EADDRINUSE line, find the process with lsof and stop it the same way. After stopping it, the tests passed when I ran them with the same config.





