slidevjs/slidev · error · TypeError

Invalid timestamp format

Error message

Invalid timestamp format

What it means

parseTimeString only accepts colon-timestamps with exactly 1, 2, or 3 components (ss, mm:ss, hh:mm:ss). This first guard fires when the split produced any other number of parts (e.g. 4+).

Source

Thrown at packages/parser/src/timesplit/timestring.ts:52

  if (timestamp.includes(':')) {
    const parts = timestamp.split(':').map(Number)
    let h = 0
    let m = 0
    let s = 0
    if (parts.length === 3) {
      h = parts[0]
      m = parts[1]
      s = parts[2]
    }
    else if (parts.length === 2) {
      m = parts[0]
      s = parts[1]
    }
    else if (parts.length === 1) {
      s = parts[0]
    }
    else {
      throw new TypeError('Invalid timestamp format')
    }
    if (Number.isNaN(h) || Number.isNaN(m) || Number.isNaN(s)) {
      throw new TypeError('Invalid timestamp format')
    }
    seconds = (h || 0) * 3600 + (m || 0) * 60 + (s || 0)
  }
  else if (!RE_ALPHA.test(timestamp)) {
    seconds = Number(timestamp)
  }
  else {
    const unitMap: Record<string, number> = {
      s: 1,
      sec: 1,
      secs: 1,
      m: 60,
      min: 60,
      mins: 60,
      h: 3600,

View on GitHub (pinned to 0d798ace58)

Solutions

  1. Use ss, mm:ss, or hh:mm:ss form only
  2. Remove extra colons from the timestamp
  3. Switch to a unit-based form (e.g. 90s) if the value is awkward

Example fix

// before
timesplit: 1:2:3:4
// after
timesplit: 1:02:03
Defensive patterns

Strategy: validation

Validate before calling

function validColonParts(ts: string): boolean {
  if (!ts.includes(':')) return true
  const parts = ts.split(':')
  return parts.length >= 1 && parts.length <= 3 && parts.every(p => Number.isFinite(Number(p)))
}

Type guard

function isColonTimestamp(ts: string): ts is string {
  return ts.includes(':') && ts.split(':').length <= 3
}

Prevention

When it happens

Trigger: Passing a string like '1:2:3:4' (4 parts) or an empty/edge string that splits into 0 or 4+ parts.

Common situations: Extra colons, pasting timestamps with sub-frame counters, malformed user input.

Related errors


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