{"record":{"id":"c1fab8be48c1d094","repo":"slidevjs/slidev","slug":"failed-to-resolve-package-dep","errorCode":null,"errorMessage":"Failed to resolve package \"${dep}\"","messagePattern":"Failed to resolve package \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/slidev/node/resolver.ts","lineNumber":250,"sourceCode":"  if (!confirm)\n    process.exit(1)\n\n  if (isInstalledGlobally.value)\n    await run(parseNi, ['-g', pkgName])\n  else\n    await run(parseNi, [pkgName])\n}\n\n/**\n * Find the root of the package. If Slidev is installed globally, it will also search globally.\n */\nexport async function findPkgRoot(dep: string, parent: string, ensure: true): Promise<string>\nexport async function findPkgRoot(dep: string, parent: string, ensure?: boolean): Promise<string | undefined>\nexport async function findPkgRoot(dep: string, parent: string, ensure = false) {\n  const pkgJsonPath = await findDepPkgJsonPath(dep, parent)\n  const path = pkgJsonPath ? dirname(pkgJsonPath) : isInstalledGlobally.value ? await findGlobalPkgRoot(dep, false) : undefined\n  if (ensure && !path)\n    throw new Error(`Failed to resolve package \"${dep}\"`)\n  return path\n}\n\nexport async function findGlobalPkgRoot(name: string, ensure: true): Promise<string>\nexport async function findGlobalPkgRoot(name: string, ensure?: boolean): Promise<string | undefined>\nexport async function findGlobalPkgRoot(name: string, ensure = false) {\n  const localPath = await findDepPkgJsonPath(name, cliRoot)\n  if (localPath)\n    return dirname(localPath)\n  for (const nm of invocationSearchPaths) {\n    const direct = join(nm, ...name.split('/'), 'package.json')\n    if (existsSync(direct))\n      return dirname(direct)\n    const walked = await findDepPkgJsonPath(name, nm)\n    if (walked)\n      return dirname(walked)\n  }\n  const yarnPath = join(globalDirs.yarn.packages, name)","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/slidevjs/slidev/blob/0d798ace5828966d9f77f62094d5f7a971ad98f7/packages/slidev/node/resolver.ts#L232-L268","documentation":"Thrown by findPkgRoot(dep, parent, ensure: true) when the package root cannot be located: findDepPkgJsonPath returned nothing from the parent tree, and (in global mode) findGlobalPkgRoot also returned nothing. The ensure: true overload always returns a string or throws.","triggerScenarios":"Calling findPkgRoot(dep, parent, true) for a dependency that is not installed in the parent's node_modules tree and not installed globally. Internally used by getRoots() to find @slidev/client, and by createResolver after a prompted install.","commonSituations":"A fresh/corrupted Slidev install where @slidev/client is missing; a dependency listed in package.json but not actually installed (broken lockfile); running in an environment where node_modules was pruned.","solutions":["Reinstall dependencies at the project root: npm install / pnpm install --force.","Confirm the dep is present: ls node_modules/<dep> or check package.json dependencies.","If Slidev itself is the dep (e.g. @slidev/client), reinstall @slidev/cli.","For monorepos, ensure the workspace is hoisted/linked so findDepPkgJsonPath can walk to the dep."],"exampleFix":"// before: @slidev/client missing after a botched upgrade\nfindPkgRoot('@slidev/client', cliRoot, true) // throws\n\n// after: reinstall the cli (brings client back)\n// shell:\nnpm i -D @slidev/cli@latest","handlingStrategy":"try-catch","validationCode":"import { findDepPkgJsonPath } from 'vitefu'\n\nasync function pkgRootExists(dep: string, parent: string): Promise<boolean> {\n  try {\n    return !!(await findDepPkgJsonPath(dep, parent))\n  } catch {\n    return false\n  }\n}\n\n// before findPkgRoot(dep, parent, true):\nif (!await pkgRootExists(dep, parent)) {\n  throw new Error(`Reinstall dependencies; ${dep} not found under ${parent}`)\n}","typeGuard":"async function pkgResolvable(dep: string, parent: string): Promise<boolean> {\n  try {\n    return !!(await findDepPkgJsonPath(dep, parent))\n  } catch {\n    return false\n  }\n}","tryCatchPattern":"try {\n  return await findPkgRoot(dep, parent, true)\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Failed to resolve package ')) {\n    throw new Error(`${dep} not installed; run npm install and retry.`)\n  }\n  throw e\n}","preventionTips":["Run npm install / pnpm install after every package.json change.","For core packages like @slidev/client, reinstall @slidev/cli if missing.","In monorepos, verify workspace hoisting reaches the consuming package.","Use a frozen lockfile in CI to detect missing deps early."],"tags":["resolver","dependencies","install","node-modules"],"backgroundTag":null,"analyzedSha":"0d798ace5828966d9f77f62094d5f7a971ad98f7","analyzedAt":"2026-08-12T17:10:56.221Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}