vitest-dev/vitest · error · Error

Inspector host cannot be a URL. Use "host:port" instead of

Error message

Inspector host cannot be a URL. Use "host:port" instead of "${inspect}"

What it means

`parseInspector` converts the `--inspect`/`--inspect-brk` value into `{ host, port }`. It accepts a boolean, a number (treated as a port), or a `host:port` string — but explicitly rejects values that look like a URL (`/https?:\//`). The fix is to drop the scheme and pass `host:port`.

Solutions

  1. Pass `host:port`: `vitest --inspect=localhost:9229`.
  2. Pass just a port: `vitest --inspect=9229`.
  3. Use bare `--inspect` to enable with defaults.

Example fix

# before
vitest --inspect=http://localhost:9229

# after
vitest --inspect=localhost:9229
Defensive patterns

Strategy: validation

Validate before calling

function parseInspectValue(v: unknown): { host?: string; port?: number } {
  if (typeof v === 'boolean' || v == null) return {}
  if (typeof v === 'number') return { port: v }
  const s = String(v)
  if (/^https?:\/\//.test(s)) {
    throw new Error('Pass host:port to --inspect, not a URL')
  }
  const [host, port] = s.split(':')
  return port ? { host, port: Number(port) || 9229 } : { host }
}

Prevention

When it happens

Trigger: Running `vitest --inspect=http://localhost:9229`, `--inspect-brk=ws://host:9229`, or pasting a DevTools URL from another tool. The regex test trips before host/port splitting.

Common situations: Copy-pasting a Chrome DevTools `ws://` URL; confusing Vitest's `--inspect` with `node --inspect`; tooling that emits URLs for inspector connections.

Related errors


AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11). Data as JSON: /api/errors/baa1db3d19f83413. Report an issue: GitHub.

Appendix: source

Thrown at packages/vitest/src/node/config/resolveConfig.ts:77

export function findConfigFile(root: string): string | undefined {
  for (const configFile of configFiles) {
    const configPath = resolve(root, configFile)
    if (existsSync(configPath)) {
      return configPath
    }
  }
}

function parseInspector(inspect: string | undefined | boolean | number) {
  if (typeof inspect === 'boolean' || inspect === undefined) {
    return {}
  }
  if (typeof inspect === 'number') {
    return { port: inspect }
  }

  if (/https?:\//.test(inspect)) {
    throw new Error(
      `Inspector host cannot be a URL. Use "host:port" instead of "${inspect}"`,
    )
  }

  const [host, port] = inspect.split(':')
  if (!port) {
    return { host }
  }
  return { host, port: Number(port) || defaultInspectPort }
}

export function resolveApiServerConfig(
  config: UserConfig,
  defaultPort: number,
  logger: Logger,
): ApiConfig {
  const isBrowserEnabled = !!config.browser?.enabled

View on GitHub (pinned to 1fa9837ec2)