slidevjs/slidev · error · Error

Failed to get Vite server port

Error message

Failed to get Vite server port

What it means

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.

Source

Thrown at packages/slidev/node/cli.ts:611

      }
      finally {
        await server?.close()
      }
    }

    process.exit(0)
  },
)

cli
  .help()
  .parse()

function getViteServerPort(server: ViteDevServer): number {
  const address = server.httpServer?.address()
  if (address && typeof address === 'object')
    return address.port
  throw new Error('Failed to get Vite server port')
}

function commonOptions(args: Argv<object>) {
  return args
    .positional('entry', {
      default: 'slides.md',
      type: 'string',
      describe: 'path to the slides markdown entry',
    })
    .option('theme', {
      alias: 't',
      type: 'string',
      describe: 'override theme',
    })
}

function exportOptions<T>(args: Argv<T>) {
  return args

View on GitHub (pinned to 0d798ace58)

Solutions

  1. Pass an explicit --port that is free
  2. Free or kill whatever holds the chosen port
  3. Run with permissions for low ports (<1024) if used

Example fix

// before
slidev
// after
slidev --port 3030
Defensive patterns

Strategy: try-catch

Validate before calling

// after server.listen resolves, verify address shape
const addr = server.httpServer?.address()
if (!addr || typeof addr !== 'object') {
  throw new Error('Vite server did not bind to a TCP port; pass --port')
}

Type guard

function isTcpAddress(addr: any): addr is { port: number } {
  return !!addr && typeof addr === 'object' && typeof addr.port === 'number'
}

Try / catch

try {
  const port = getViteServerPort(server)
} catch (e) {
  // retry with an explicit free port
  server.close()
  return startWithPort(0)
}

Prevention

When it happens

Trigger: The HTTP server failed to bind (port in use / no permission), or is using a Unix socket/pipe transport that returns a string address.

Common situations: Port conflicts, restricted low ports, an abnormal server lifecycle, or custom server configs that bind to a socket.

Related errors


AI-assisted analysis of slidevjs/slidev@0d798ace58 (2026-08-12). Data as JSON: /api/errors/36b64d238504b86e. Report an issue: GitHub.