{"record":{"id":"95ea41747ed720e6","repo":"slidevjs/slidev","slug":"code-snippet-path-not-found-src","errorCode":null,"errorMessage":"Code snippet path not found: ${src}","messagePattern":"Code snippet path not found: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slidev/node/syntax/snippet.ts","lineNumber":133,"sourceCode":"\n  let [, filepath = '', regionName = '', lang = '', meta = ''] = match\n  const dir = path.dirname(slide.source.filepath)\n  const src = slash(\n    filepath.startsWith('@/')\n      ? path.resolve(userRoot, filepath.slice(2))\n      : path.resolve(dir, filepath),\n  )\n\n  lang = lang.trim() || path.extname(filepath).slice(1)\n  meta = meta.trim()\n\n  if (!isPathInsideRoots(src, allowedRoots)) {\n    throw new Error(`Code snippet path escapes the project root: ${src}`)\n  }\n\n  const isAFile = fs.existsSync(src) && fs.statSync(src).isFile()\n  if (!isAFile) {\n    throw new Error(`Code snippet path not found: ${src}`)\n  }\n\n  let content = fs.readFileSync(src, 'utf8')\n\n  if (regionName) {\n    const lines = content.split(RE_NEWLINE)\n    const region = findRegion(lines, regionName.slice(1))\n    if (region) {\n      content = dedent(\n        lines\n          .slice(region.start, region.end)\n          .filter(l => !(region.re.start.test(l) || region.re.end.test(l)))\n          .join('\\n'),\n      )\n    }\n  }\n\n  return { content, filepath, lang, meta, src }","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/slidevjs/slidev/blob/0d798ace5828966d9f77f62094d5f7a971ad98f7/packages/slidev/node/syntax/snippet.ts#L115-L151","documentation":"Thrown by resolveSnippetImport when the snippet path passed isPathInsideRoots but does not exist on disk or is not a regular file (fs.existsSync false, or fs.statSync(...).isFile() false). Fires at parse time during markdown rendering of a <<< import line.","triggerScenarios":"Writing <<< ./missing.ts or <<< @/typo/file.js where the target file does not exist, or where the path resolves to a directory rather than a file.","commonSituations":"Typo in the snippet path; file renamed/deleted after the slide was written; case-sensitivity mismatch on case-sensitive filesystems (Linux) when authoring on macOS/Windows; pointing at a directory by mistake.","solutions":["Verify the file exists at the resolved absolute path the error prints.","Correct typos and case in the snippet path.","If the file was moved, update the import to its new location.","Ensure the path points to a file, not a directory."],"exampleFix":"// before: wrong filename (typo)\n<<< ./src/snippit.ts\n\n// after: correct filename\n<<< ./src/snippet.ts","handlingStrategy":"validation","validationCode":"import fs from 'node:fs'\nimport path from 'pathe'\n\nfunction snippetFileExists(dir: string, userRoot: string, filepath: string): boolean {\n  const src = filepath.startsWith('@/')\n    ? path.resolve(userRoot, filepath.slice(2))\n    : path.resolve(dir, filepath)\n  return fs.existsSync(src) && fs.statSync(src).isFile()\n}\n\n// before relying on a <<< import:\nif (!snippetFileExists(slideDir, userRoot, filepath)) {\n  throw new Error(`Snippet file missing: ${filepath}`)\n}","typeGuard":"function snippetFileResolves(dir: string, userRoot: string, filepath: string): boolean {\n  const src = filepath.startsWith('@/')\n    ? path.resolve(userRoot, filepath.slice(2))\n    : path.resolve(dir, filepath)\n  try {\n    return fs.existsSync(src) && fs.statSync(src).isFile()\n  } catch {\n    return false\n  }\n}","tryCatchPattern":"try {\n  return resolveSnippetImport(line, userRoot, slide, allowedRoots)\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Code snippet path not found')) {\n    // surface the resolved path; offer to create or fix the import\n    return null\n  }\n  throw e\n}","preventionTips":["Verify snippet target files exist (case-correctly) before referencing them.","On case-sensitive filesystems, double-check capitalization of paths authored on macOS/Windows.","Run a lint pass that checks every <<< import resolves to a file.","When moving/renaming source files, grep the deck for stale <<< references."],"tags":["syntax","snippet","filesystem","missing-file"],"backgroundTag":null,"analyzedSha":"0d798ace5828966d9f77f62094d5f7a971ad98f7","analyzedAt":"2026-08-12T17:10:56.221Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}