{"id":"1b93d9782900a563","repo":"vitejs/vite","slug":"port-port-is-already-in-use","errorCode":null,"errorMessage":"Port ${port} is already in use","messagePattern":"Port (.+?) is already in use","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/http.ts","lineNumber":252,"sourceCode":"    // If port is not available on a wildcard address but strictPort is set,\n    // we still try binding directly before giving up.\n    if (strictPort) {\n      const result = await tryBindServer(httpServer, port, host)\n      if (result.success) {\n        if (!portAvailableOnWildcard) {\n          logger.warn(\n            colors.yellow(\n              `Port ${port} is in use on a wildcard address, but ${host ?? 'localhost'}:${port} is available. ` +\n                `There may be another server running on a wildcard IP on port ${port}.`,\n            ),\n          )\n        }\n        return port\n      }\n      if (result.error.code !== 'EADDRINUSE') {\n        throw result.error\n      }\n      throw new Error(`Port ${port} is already in use`)\n    }\n\n    if (portAvailableOnWildcard) {\n      const result = await tryBindServer(httpServer, port, host)\n      if (result.success) {\n        return port\n      }\n      if (result.error.code !== 'EADDRINUSE') {\n        throw result.error\n      }\n    }\n    logger.info(`Port ${port} is in use, trying another one...`)\n  }\n  throw new Error(\n    `No available ports found between ${startPort} and ${MAX_PORT}`,\n  )\n}\n","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/src/node/http.ts#L234-L270","documentation":"Thrown by `httpServer` port resolution when `strictPort: true` and the requested port cannot be bound (the bind attempt returns `EADDRINUSE`). With strictPort Vite refuses to silently move to another port, so it surfaces the conflict directly. The throw is at http.ts:252, after re-binding confirms the failure is an in-use error.","triggerScenarios":"Starting `createServer`/`createPreviewServer` with `server.strictPort: true` (or `preview.strictPort: true`) while the configured `server.port` is already bound by another process.","commonSituations":"A previous dev server didn't shut down cleanly; another app (or a second Vite instance) holds the port; Docker/WSL port forwarding conflicts; running multiple projects on port 5173/3000.","solutions":["Free the port: find the process with `lsof -i :<port>` / `netstat -ano` and stop it, or restart your machine/WSL.","Set `strictPort: false` (default) so Vite auto-increments to the next free port.","Change `server.port` to a free port in the config.","If the holder is your own orphaned process, run `tman kill`/`kill -9 <pid>`."],"exampleFix":"// before\nexport default defineConfig({ server: { port: 5173, strictPort: true } })\n\n// after\nexport default defineConfig({ server: { port: 5173, strictPort: false } })","handlingStrategy":"validation","validationCode":"import net from 'node:net'\nasync function isFree(port: number, host?: string): Promise<boolean> {\n  return new Promise((res) => {\n    const s = net.createServer()\n    s.unref().once('error', () => res(false)).listen(port, host, () => s.close(() => res(true)))\n  })\n}\n// before createServer: if (config.server.strictPort && !(await isFree(port))) throw ...","typeGuard":null,"tryCatchPattern":"try {\n  await createServer(config)\n} catch (e) {\n  if (e instanceof Error && /already in use/.test(e.message)) {\n    // free the port or switch config.server.port / strictPort and retry once\n  } else throw e\n}","preventionTips":["Pre-check port availability before strictPort binds.","Default strictPort to false in shared/team configs to avoid hard failures.","Use a deterministic per-project port to reduce collisions."],"tags":["server","network","port","config"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}