{"record":{"id":"36b64d238504b86e","repo":"slidevjs/slidev","slug":"failed-to-get-vite-server-port","errorCode":null,"errorMessage":"Failed to get Vite server port","messagePattern":"Failed to get Vite server port","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slidev/node/cli.ts","lineNumber":611,"sourceCode":"      }\n      finally {\n        await server?.close()\n      }\n    }\n\n    process.exit(0)\n  },\n)\n\ncli\n  .help()\n  .parse()\n\nfunction getViteServerPort(server: ViteDevServer): number {\n  const address = server.httpServer?.address()\n  if (address && typeof address === 'object')\n    return address.port\n  throw new Error('Failed to get Vite server port')\n}\n\nfunction commonOptions(args: Argv<object>) {\n  return args\n    .positional('entry', {\n      default: 'slides.md',\n      type: 'string',\n      describe: 'path to the slides markdown entry',\n    })\n    .option('theme', {\n      alias: 't',\n      type: 'string',\n      describe: 'override theme',\n    })\n}\n\nfunction exportOptions<T>(args: Argv<T>) {\n  return args","sourceCodeStart":593,"sourceCodeEnd":629,"githubUrl":"https://github.com/slidevjs/slidev/blob/0d798ace5828966d9f77f62094d5f7a971ad98f7/packages/slidev/node/cli.ts#L593-L629","documentation":"After starting the Vite dev server, Slidev reads server.httpServer.address(). It only accepts a TCP address object (which exposes .port). If the address is null/undefined (server not bound) or a string (pipe/unix socket), it cannot extract a port and throws.","triggerScenarios":"The HTTP server failed to bind (port in use / no permission), or is using a Unix socket/pipe transport that returns a string address.","commonSituations":"Port conflicts, restricted low ports, an abnormal server lifecycle, or custom server configs that bind to a socket.","solutions":["Pass an explicit --port that is free","Free or kill whatever holds the chosen port","Run with permissions for low ports (<1024) if used"],"exampleFix":"// before\nslidev\n// after\nslidev --port 3030","handlingStrategy":"try-catch","validationCode":"// after server.listen resolves, verify address shape\nconst addr = server.httpServer?.address()\nif (!addr || typeof addr !== 'object') {\n  throw new Error('Vite server did not bind to a TCP port; pass --port')\n}","typeGuard":"function isTcpAddress(addr: any): addr is { port: number } {\n  return !!addr && typeof addr === 'object' && typeof addr.port === 'number'\n}","tryCatchPattern":"try {\n  const port = getViteServerPort(server)\n} catch (e) {\n  // retry with an explicit free port\n  server.close()\n  return startWithPort(0)\n}","preventionTips":["Pass an explicit --port to avoid bind-time ambiguity","Free conflicting ports before starting the dev server"],"tags":["cli","vite","server","port"],"backgroundTag":null,"analyzedSha":"0d798ace5828966d9f77f62094d5f7a971ad98f7","analyzedAt":"2026-08-12T17:10:56.221Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}