slidevjs/slidev · error · TypeError
Invalid timestamp unit: ${unit}
Error message
Invalid timestamp unit: ${unit} What it means
The unit-based parser only recognizes a fixed set of units (s/sec/secs, m/min/mins, h/hr/hrs/hour/hours, day/days, week/weeks, month/months, year/years). Any other suffix throws.
Source
Thrown at packages/parser/src/timesplit/timestring.ts:94
days: 86400,
week: 604800,
weeks: 604800,
month: 2629746,
months: 2629746,
year: 31556952,
years: 31556952,
}
const regex = /([\d.]+)([a-z]+)/gi
const matches = timestamp.matchAll(regex)
if (matches) {
for (const match of matches) {
const value = Number(match[1])
if (Number.isNaN(value)) {
throw new TypeError(`Invalid timestamp value: ${match[1]}`)
}
const unit = match[2].toLowerCase()
if (!(unit in unitMap)) {
throw new TypeError(`Invalid timestamp unit: ${unit}`)
}
seconds += value * unitMap[unit]
}
}
const remaining = timestamp.replace(regex, '').trim()
if (remaining) {
throw new TypeError(`Unknown timestamp remaining: ${remaining}`)
}
}
return {
seconds,
relative,
}
}
View on GitHub (pinned to 0d798ace58)
Solutions
- Use one of the supported unit names (s, sec, m, min, h, hr, day, week, month, year and plurals)
- Convert sub-second values to a fractional second (0.5s)
- Double-check the spelling of the unit
Example fix
// before timesplit: 5ms // after timesplit: 0.005s
Defensive patterns
Strategy: validation
Validate before calling
const SUPPORTED_UNITS = new Set(['s','sec','secs','m','min','mins','h','hr','hrs','hour','hours','day','days','week','weeks','month','months','year','years'])
function validUnits(ts: string): boolean {
return Array.from(ts.matchAll(/([\d.]+)([a-z]+)/gi)).every(m => SUPPORTED_UNITS.has(m[2].toLowerCase()))
} Type guard
function isSupportedUnit(u: string): u is string {
const set = new Set(['s','sec','secs','m','min','mins','h','hr','hrs','hour','hours','day','days','week','weeks','month','months','year','years'])
return set.has(u.toLowerCase())
} Prevention
- Spellcheck unit suffixes against the supported list
- Use fractional seconds instead of ms/us
When it happens
Trigger: Writing 5ms (milliseconds unsupported), 5secounds (typo), or any unrecognized unit string.
Common situations: Typos, assuming ms/us are supported, locale-specific abbreviations.
Related errors
- Invalid timestamp format
- Invalid timestamp value: ${match[1]}
- Unknown timestamp remaining: ${remaining}
- Timesplit end ${end} is before start ${ts}
- Invalid aspect ratio "${str}"
AI-assisted analysis of slidevjs/slidev@0d798ace58 (2026-08-12).
Data as JSON: /api/errors/0aebd03ab2c97857.
Report an issue: GitHub.