slidevjs/slidev · error · Error
Invalid aspect ratio "${str}"
Error message
Invalid aspect ratio "${str}" What it means
parseAspectRatio accepts a number, a numeric string, or a '<w><sep><h>' string where sep is one of the aspect-ratio separators. After splitting, both sides must be finite numbers and the height must be non-zero.
Source
Thrown at packages/parser/src/utils.ts:46
}
return uniq(indexes).filter(i => i <= total).sort((a, b) => a - b)
}
/**
* Accepts `16/9` `1:1` `3x4`
*/
export function parseAspectRatio(str: string | number) {
if (isNumber(str))
return str
if (!Number.isNaN(+str))
return +str
const [wStr = '', hStr = ''] = str.split(RE_ASPECT_RATIO_SEPARATOR)
const w = Number.parseFloat(wStr.trim())
const h = Number.parseFloat(hStr.trim())
if (Number.isNaN(w) || Number.isNaN(h) || h === 0)
throw new Error(`Invalid aspect ratio "${str}"`)
return w / h
}
View on GitHub (pinned to 0d798ace58)
Solutions
- Use one of the documented forms: 16/9, 1:1, 3x4, or a plain number like 1.7778
- Ensure both sides are numeric and the second is non-zero
- Use a recognized separator (/ : or x)
Example fix
// before aspectRatio: 16_9 // after aspectRatio: 16/9
Defensive patterns
Strategy: validation
Validate before calling
function validAspectRatio(v: string | number): boolean {
if (typeof v === 'number' || !Number.isNaN(+v)) return +v > 0
const [w = '', h = ''] = String(v).split(/[\/:x]/)
const wn = Number.parseFloat(w.trim()), hn = Number.parseFloat(h.trim())
return Number.isFinite(wn) && Number.isFinite(hn) && hn !== 0
} Type guard
function isAspectRatioInput(v: unknown): v is string | number {
return typeof v === 'number' || (typeof v === 'string' && /^\s*[\d.]+\s*[\/:x]\s*[\d.]+\s*$/.test(v))
} Prevention
- Use 16/9 / 1:1 / 3x4 or a plain number for aspectRatio
- Reject zero or empty height in any custom config validator
When it happens
Trigger: Setting aspectRatio to a non-numeric string, an incomplete pair ('16/'), a zero height ('16/0'), or using an unsupported separator like underscore.
Common situations: Typos, unsupported separators, dividing by zero, pasting values like '16_9'.
Related errors
- [slidev] "prism" support has been dropped. Please use "highl
- Invalid timestamp format
- Invalid timestamp value: ${match[1]}
- Invalid timestamp unit: ${unit}
- Unknown timestamp remaining: ${remaining}
AI-assisted analysis of slidevjs/slidev@0d798ace58 (2026-08-12).
Data as JSON: /api/errors/b75a1356ae6ba7b6.
Report an issue: GitHub.