slidevjs/slidev · error · Error
Slide ${anchorNo} is out of sync with its source file. Try a
Error message
Slide ${anchorNo} is out of sync with its source file. Try again. What it means
Thrown by moveSlide when md.slides.indexOf(anchor.source) < 0 after the 'from' slide was already spliced out, i.e. the anchor slide's SourceSlideInfo is not in its file's slides array. Same consistency-guard family as the from-side check; indicates the anchor's source object is stale.
Source
Thrown at packages/slidev/node/mcp/operations.ts:200
throw new Error(
`Cannot move a slide across markdown files: slide ${from} is in "${slide.source.filepath}" `
+ `but slide ${anchorNo} is in "${anchor.source.filepath}" (imported with \`src:\`). `
+ `Move it within its own file, or edit the \`src:\` imports in the entry file manually.`,
)
}
assertNotEntryHeadmatter(data, slide.source, 'move')
if (before != null)
assertNotEntryHeadmatter(data, anchor.source, 'insert a slide before')
const md = getMarkdown(data, slide.source)
const fromIdx = md.slides.indexOf(slide.source)
if (fromIdx < 0)
throw new Error(`Slide ${from} is out of sync with its source file. Try again.`)
md.slides.splice(fromIdx, 1)
const anchorIdx = md.slides.indexOf(anchor.source)
if (anchorIdx < 0)
throw new Error(`Slide ${anchorNo} is out of sync with its source file. Try again.`)
md.slides.splice(before != null ? anchorIdx : anchorIdx + 1, 0, slide.source)
const fileContent = await parser.save(md)
return { moved: slide, anchor, filepath: md.filepath, fileContent }
}
View on GitHub (pinned to 0d798ace58)
Solutions
- Re-fetch data via ctx.getData() right before moveSlide and retry.
- Confirm the anchor slide still exists via slidev-list-slides before reissuing the move.
- Prevent concurrent writers on the same markdown file.
Example fix
// before: anchor reference stale after an external edit
const data = await ctx.getData()
await moveSlide(data, { from: 2, before: 5 }) // throws: anchor out of sync
// after: refresh and re-resolve anchor
const data = await ctx.getData()
await moveSlide(data, { from: 2, before: 5 }) Defensive patterns
Strategy: retry
Validate before calling
function anchorSlideInFile(md: { slides: SourceSlideInfo[] }, source: SourceSlideInfo): boolean {
return md.slides.indexOf(source) >= 0
}
// before moveSlide, validate the anchor too:
const anchor = resolveSlide(data, before ?? after!)
const md = data.markdownFiles[anchor.source.filepath]
if (!md || !anchorSlideInFile(md, anchor.source)) return // refresh Type guard
function anchorSourceCurrent(md: { slides: SourceSlideInfo[] }, s: SourceSlideInfo): s is SourceSlideInfo {
return md.slides.indexOf(s) >= 0
} Try / catch
try {
return await moveSlide(data, opts)
} catch (e) {
const anchorNo = opts.before ?? opts.after
if (e instanceof Error && new RegExp(`Slide ${anchorNo} is out of sync`).test(e.message)) {
data = await ctx.getData()
return await moveSlide(data, opts)
}
throw e
} Prevention
- Validate both from and anchor sources against their file's slides array before splicing.
- Refresh ctx.getData() per mutation.
- Serialize writers per markdown file.
- After any external edit, reload and re-list before reissuing the move.
When it happens
Trigger: Calling moveSlide where the anchor (before/after) slide's source is no longer a member of md.slides, typically because external edits invalidated the object reference between getData() and the call.
Common situations: Concurrent edits to the anchor's file; stale getData() snapshot; anchor imported via src: from a file that was modified.
Related errors
- Slide ${from} is out of sync with its source file. Try again
- Slide ${no} is out of sync with its source file. Try again.
- Markdown file not loaded: ${source.filepath}
- Specify exactly one of `before` or `after`.
- The `before`/`after` anchor must be a different slide than `
AI-assisted analysis of slidevjs/slidev@0d798ace58 (2026-08-12).
Data as JSON: /api/errors/7429547f0af3a06a.
Report an issue: GitHub.