slidevjs/slidev · critical · Error
Failed to resolve package "${importName}"
Error message
Failed to resolve package "${importName}" What it means
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).
Source
Thrown at packages/slidev/node/resolver.ts:166
catch { }
if (isInstalledGlobally.value) {
for (const nm of invocationSearchPaths) {
try {
return await resolvePath(importName, {
url: pathToFileURL(`${nm}${sep}`),
})
}
catch { }
}
try {
return resolveGlobal(importName)
}
catch { }
}
if (ensure)
throw new Error(`Failed to resolve package "${importName}"`)
}
/**
* Import an optional dependency (typically an optional peer dependency such as
* `vite-plugin-pwa`) that the user may or may not have installed. Resolution is
* attempted, in order, from the user's project root, the workspace root, the
* global registry (when Slidev runs globally), and finally the cli's own
* dependencies. Returns `undefined` when the package can't be resolved anywhere.
*/
export async function importOptionalDependency<T = any>(name: string): Promise<T | undefined> {
const roots: string[] = []
try {
const { userRoot, userWorkspaceRoot } = await getRoots()
roots.push(userRoot)
if (userWorkspaceRoot !== userRoot)
roots.push(userWorkspaceRoot)
}
catch { }View on GitHub (pinned to 0d798ace58)
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.
Example fix
// before: vite plugin missing locally
resolveImportPath('vite-plugin-pwa', true) // throws
// after: install it
// shell:
npm i -D vite-plugin-pwa Defensive patterns
Strategy: try-catch
Validate before calling
import { resolvePath } from 'mlly'
import { existsSync } from 'node:fs'
async function isResolvable(name: string): Promise<boolean> {
try {
await resolvePath(name, { url: import.meta.url })
return true
} catch {
return false
}
}
// before resolveImportPath(name, true):
if (!await isResolvable(name)) {
throw new Error(`Install ${name} first: npm i -D ${name}`)
} Type guard
async function isImportable(name: string): Promise<boolean> {
try {
await import(name)
return true
} catch {
return false
}
} Try / catch
try {
return await resolveImportPath(name, true)
} catch (e) {
if (e instanceof Error && e.message.startsWith('Failed to resolve package ')) {
// prompt to install, or fall back to optional dependency handling
throw new Error(`Missing dependency ${name}; run npm i -D ${name}`)
}
throw e
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to resolve package "${dep}"
- 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/2fb99d58b23a085a.
Report an issue: GitHub.