slidevjs/slidev · error · Error

Cannot move a slide across markdown files: slide ${from} is

Error message

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.

What it means

Thrown by moveSlide when slide.source.filepath !== anchor.source.filepath. moveSlide only reorders within a single markdown file; slides imported via the src: directive live in separate files and cannot be moved across the import boundary by this tool.

Source

Thrown at packages/slidev/node/mcp/operations.ts:182

}

/**
 * Move a slide before or after another slide within the same markdown file.
 */
export async function moveSlide(data: LoadedSlidevData, options: MoveSlideOptions): Promise<MoveSlideResult> {
  const { from, before, after } = options
  if ((before == null) === (after == null))
    throw new Error('Specify exactly one of `before` or `after`.')

  const anchorNo = (before ?? after)!
  if (anchorNo === from)
    throw new Error('The `before`/`after` anchor must be a different slide than `from`.')

  const slide = resolveSlide(data, from)
  const anchor = resolveSlide(data, anchorNo)

  if (slide.source.filepath !== anchor.source.filepath) {
    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.`)

View on GitHub (pinned to 0d798ace58)

Solutions

  1. Move the slide within its own source file (re-fetch the data, find its file, and choose an anchor in the same file).
  2. To relocate across files, edit the src: imports in the entry markdown by hand (reorder/repoint the import lines) and reload.
  3. Run slidev-list-slides and check the 'file' field per slide to confirm both share a filepath before calling moveSlide.

Example fix

// before: from in slides.md, anchor in chapter1.md (imported via src:)
await tools['slidev-move-slide']({ from: 2, before: 6 }) // throws

// after: pick an anchor in the same file as slide 2
// (list-slides shows slide 2 and slide 4 both in ./slides.md)
await tools['slidev-move-slide']({ from: 2, before: 4 })
Defensive patterns

Strategy: validation

Validate before calling

function sameFile(a: SourceSlideInfo, b: SourceSlideInfo): boolean {
  return a.filepath === b.filepath
}

// before moveSlide:
const data = await ctx.getData()
const slide = resolveSlide(data, from)
const anchor = resolveSlide(data, before ?? after!)
if (!sameFile(slide.source, anchor.source)) {
  throw new Error('Use update on src: imports or move within the same file.')
}

Type guard

function slidesShareFile(a: SlideInfo, b: SlideInfo): boolean {
  return a.source.filepath === b.source.filepath
}

Try / catch

try {
  await moveSlide(data, { from, before, after })
} catch (e) {
  if (e instanceof Error && /Cannot move a slide across markdown files/.test(e.message)) {
    // fall back: edit the src: import order in the entry markdown
    return { error: 'Cross-file move blocked; reorder src: imports manually.' }
  }
  throw e
}

Prevention

When it happens

Trigger: Calling slidev-move-slide where from and before/after resolve to slides whose source.filepath differ - one or both come from a file pulled in through src: imports.

Common situations: A modular deck splits slides into multiple .md files via src:; an agent addresses rendered numbers without checking they share a source file; trying to move an imported slide into the entry file (or vice versa).

Related errors


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