{"record":{"id":"2fb99d58b23a085a","repo":"slidevjs/slidev","slug":"failed-to-resolve-package-importname","errorCode":null,"errorMessage":"Failed to resolve package \"${importName}\"","messagePattern":"Failed to resolve package \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/slidev/node/resolver.ts","lineNumber":166,"sourceCode":"  catch { }\n\n  if (isInstalledGlobally.value) {\n    for (const nm of invocationSearchPaths) {\n      try {\n        return await resolvePath(importName, {\n          url: pathToFileURL(`${nm}${sep}`),\n        })\n      }\n      catch { }\n    }\n    try {\n      return resolveGlobal(importName)\n    }\n    catch { }\n  }\n\n  if (ensure)\n    throw new Error(`Failed to resolve package \"${importName}\"`)\n}\n\n/**\n * Import an optional dependency (typically an optional peer dependency such as\n * `vite-plugin-pwa`) that the user may or may not have installed. Resolution is\n * attempted, in order, from the user's project root, the workspace root, the\n * global registry (when Slidev runs globally), and finally the cli's own\n * dependencies. Returns `undefined` when the package can't be resolved anywhere.\n */\nexport async function importOptionalDependency<T = any>(name: string): Promise<T | undefined> {\n  const roots: string[] = []\n  try {\n    const { userRoot, userWorkspaceRoot } = await getRoots()\n    roots.push(userRoot)\n    if (userWorkspaceRoot !== userRoot)\n      roots.push(userWorkspaceRoot)\n  }\n  catch { }","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/slidevjs/slidev/blob/0d798ace5828966d9f77f62094d5f7a971ad98f7/packages/slidev/node/resolver.ts#L148-L184","documentation":"Thrown by resolveImportPath(importName, ensure: true) after every resolution strategy fails: mlly resolvePath from the current module, global search paths (when Slidev runs globally), and resolve-global. Used for imports that Slidev treats as required (ensure: true).","triggerScenarios":"Calling resolveImportPath(name, true) for a package that is neither in the project's node_modules, the workspace, the invocation search paths, nor the global registry. Common for Vite plugins, client entry modules, or required peers.","commonSituations":"A required peer/plugin (e.g. a syntax highlighter, vite-plugin) is not installed; running Slidev globally while the dependency is project-local (or vice versa); a corrupted/partial install where the package dir exists but lacks an entry point.","solutions":["Install the named package: npm i -D <importName> (or your package manager's equivalent).","If Slidev runs globally, install the dependency globally too (npm i -g <importName>) so the global search paths find it.","Verify the package name is spelled correctly and resolvable from the project root with node -e \"require.resolve('<importName>')\".","Re-run npm install / pnpm install to repair a partial install."],"exampleFix":"// before: vite plugin missing locally\nresolveImportPath('vite-plugin-pwa', true) // throws\n\n// after: install it\n// shell:\nnpm i -D vite-plugin-pwa","handlingStrategy":"try-catch","validationCode":"import { resolvePath } from 'mlly'\nimport { existsSync } from 'node:fs'\n\nasync function isResolvable(name: string): Promise<boolean> {\n  try {\n    await resolvePath(name, { url: import.meta.url })\n    return true\n  } catch {\n    return false\n  }\n}\n\n// before resolveImportPath(name, true):\nif (!await isResolvable(name)) {\n  throw new Error(`Install ${name} first: npm i -D ${name}`)\n}","typeGuard":"async function isImportable(name: string): Promise<boolean> {\n  try {\n    await import(name)\n    return true\n  } catch {\n    return false\n  }\n}","tryCatchPattern":"try {\n  return await resolveImportPath(name, true)\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Failed to resolve package ')) {\n    // prompt to install, or fall back to optional dependency handling\n    throw new Error(`Missing dependency ${name}; run npm i -D ${name}`)\n  }\n  throw e\n}","preventionTips":["Declare all required deps in package.json and run a clean install before booting Slidev.","For optional plugins, use importOptionalDependency which returns undefined instead of throwing.","In CI, run with frozen lockfile to catch missing deps.","When running Slidev globally, install required plugins globally too."],"tags":["resolver","dependencies","install","node-modules"],"backgroundTag":null,"analyzedSha":"0d798ace5828966d9f77f62094d5f7a971ad98f7","analyzedAt":"2026-08-12T17:10:56.221Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}