slidevjs/slidev · error · Error
Invalid YAML frontmatter: ${parsed.errors.map(e => e.message
Error message
Invalid YAML frontmatter: ${parsed.errors.map(e => e.message).join('; ')} What it means
Thrown inside applySlidePatch when patch.frontmatterRaw is non-empty and YAML.parseDocument(patch.frontmatterRaw) returns one or more errors. It surfaces the underlying YAML parser messages joined by '; ' so the caller can correct the syntax. Used by the raw-frontmatter update path.
Source
Thrown at packages/slidev/node/mcp/operations.ts:63
*/
export async function applySlidePatch(
data: LoadedSlidevData,
no: number,
patch: SlidePatch,
): Promise<SlidePatchResult> {
const slide = resolveSlide(data, no)
const source = slide.source
if (patch.content != null)
source.content = patch.content
if (patch.frontmatterRaw != null) {
if (patch.frontmatterRaw.trim() === '') {
source.frontmatterDoc = source.frontmatterStyle = undefined
}
else {
const parsed = YAML.parseDocument(patch.frontmatterRaw)
if (parsed.errors.length)
throw new Error(`Invalid YAML frontmatter: ${parsed.errors.map(e => e.message).join('; ')}`)
source.frontmatterDoc = parsed
}
}
if (patch.note != null)
source.note = patch.note
if (patch.frontmatter)
updateFrontmatterPatch(source, patch.frontmatter)
parser.prettifySlide(source)
const fileContent = await parser.save(getMarkdown(data, source))
return { slide, fileContent }
}
export interface InsertSlideOptions {
/**
* Rendered slide number (1-based) after which the new slide is inserted.
* The new slide is inserted into the same markdown file as this slide.
*/View on GitHub (pinned to 0d798ace58)
Solutions
- Validate the YAML locally before sending: YAML.parseDocument(raw).errors must be empty.
- Use 2-space indentation and quote values containing ':', '#', or leading/trailing spaces.
- Prefer the structured frontmatter patch object (object form) over frontmatterRaw when only changing known keys.
- Run the raw block through a YAML linter/formatter (e.g. prettier with yaml plugin).
Example fix
// before: malformed raw frontmatter (tab indent)
await applySlidePatch(data, no, {
frontmatterRaw: 'layout: two-cols\n\ttransition: slide',
})
// after: valid 2-space YAML
await applySlidePatch(data, no, {
frontmatterRaw: 'layout: two-cols\n transition: slide',
}) Defensive patterns
Strategy: validation
Validate before calling
import YAML from 'yaml'
function validateFrontmatterRaw(raw: string): void {
if (raw.trim() === '') return
const parsed = YAML.parseDocument(raw)
if (parsed.errors.length) {
throw new Error(`Invalid YAML: ${parsed.errors.map(e => e.message).join('; ')}`)
}
}
// before applySlidePatch:
if (patch.frontmatterRaw != null) validateFrontmatterRaw(patch.frontmatterRaw) Type guard
function isValidYaml(raw: string): boolean {
if (raw.trim() === '') return true
return YAML.parseDocument(raw).errors.length === 0
} Try / catch
try {
await applySlidePatch(data, no, { frontmatterRaw })
} catch (e) {
if (e instanceof Error && e.message.startsWith('Invalid YAML frontmatter')) {
// show parser errors to the user, keep the draft for editing
return { error: e.message, draft: frontmatterRaw }
}
throw e
} Prevention
- Validate frontmatterRaw with YAML.parseDocument before sending.
- Prefer the structured frontmatter object patch for known keys.
- Use 2-space indentation; never tabs.
- Quote values containing ': ', '#', or leading/trailing whitespace.
- Lint YAML with prettier/yamllint in your editor.
When it happens
Trigger: Calling slidev-update-slide (or applySlidePatch directly) with a frontmatterRaw string that is not valid YAML: bad indentation, duplicate keys, unquoted special characters, tabs for indentation, or a stray ':'.
Common situations: Hand-writing frontmatter with inconsistent indentation; pasting YAML with tabs instead of spaces; using unquoted values like yes/no/on/off that YAML coerces; malformed nested mappings.
Related errors
- Slide ${no} does not exist. The deck has ${data.slides.lengt
- Specify exactly one of `before` or `after`.
- The `before`/`after` anchor must be a different slide than `
- Nothing to update: provide at least one of `content`, `note`
- [Slidev] VDrag Element ${id} is missing markdown source
AI-assisted analysis of slidevjs/slidev@0d798ace58 (2026-08-12).
Data as JSON: /api/errors/b109f537c33e53ac.
Report an issue: GitHub.