slidevjs/slidev · critical · Error
Failed to resolve package "${dep}"
Error message
Failed to resolve package "${dep}" What it means
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.
Source
Thrown at packages/slidev/node/resolver.ts:250
if (!confirm)
process.exit(1)
if (isInstalledGlobally.value)
await run(parseNi, ['-g', pkgName])
else
await run(parseNi, [pkgName])
}
/**
* Find the root of the package. If Slidev is installed globally, it will also search globally.
*/
export async function findPkgRoot(dep: string, parent: string, ensure: true): Promise<string>
export async function findPkgRoot(dep: string, parent: string, ensure?: boolean): Promise<string | undefined>
export async function findPkgRoot(dep: string, parent: string, ensure = false) {
const pkgJsonPath = await findDepPkgJsonPath(dep, parent)
const path = pkgJsonPath ? dirname(pkgJsonPath) : isInstalledGlobally.value ? await findGlobalPkgRoot(dep, false) : undefined
if (ensure && !path)
throw new Error(`Failed to resolve package "${dep}"`)
return path
}
export async function findGlobalPkgRoot(name: string, ensure: true): Promise<string>
export async function findGlobalPkgRoot(name: string, ensure?: boolean): Promise<string | undefined>
export async function findGlobalPkgRoot(name: string, ensure = false) {
const localPath = await findDepPkgJsonPath(name, cliRoot)
if (localPath)
return dirname(localPath)
for (const nm of invocationSearchPaths) {
const direct = join(nm, ...name.split('/'), 'package.json')
if (existsSync(direct))
return dirname(direct)
const walked = await findDepPkgJsonPath(name, nm)
if (walked)
return dirname(walked)
}
const yarnPath = join(globalDirs.yarn.packages, name)View on GitHub (pinned to 0d798ace58)
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.
Example fix
// before: @slidev/client missing after a botched upgrade
findPkgRoot('@slidev/client', cliRoot, true) // throws
// after: reinstall the cli (brings client back)
// shell:
npm i -D @slidev/cli@latest Defensive patterns
Strategy: try-catch
Validate before calling
import { findDepPkgJsonPath } from 'vitefu'
async function pkgRootExists(dep: string, parent: string): Promise<boolean> {
try {
return !!(await findDepPkgJsonPath(dep, parent))
} catch {
return false
}
}
// before findPkgRoot(dep, parent, true):
if (!await pkgRootExists(dep, parent)) {
throw new Error(`Reinstall dependencies; ${dep} not found under ${parent}`)
} Type guard
async function pkgResolvable(dep: string, parent: string): Promise<boolean> {
try {
return !!(await findDepPkgJsonPath(dep, parent))
} catch {
return false
}
} Try / catch
try {
return await findPkgRoot(dep, parent, true)
} catch (e) {
if (e instanceof Error && e.message.startsWith('Failed to resolve package ')) {
throw new Error(`${dep} not installed; run npm install and retry.`)
}
throw e
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to resolve package "${importName}"
- Failed to resolve global package "${name}"
- Invalid ${type} name "${name}". Only valid npm package names
- [slidev] Cannot find roots without entry
- Package "${pkg}" not found in "${importer}"
AI-assisted analysis of slidevjs/slidev@0d798ace58 (2026-08-12).
Data as JSON: /api/errors/c1fab8be48c1d094.
Report an issue: GitHub.