vitejs/vite · error · Error
The following dependencies are imported but could not be res
Error message
The following dependencies are imported but could not be resolved:
${missingIds.map(...).join(`\n `)}
Are they installed? What it means
During dependency discovery (`discoverProjectDependencies`), after `scanImports` finishes, if the `missing` map is non-empty the promise rejects with a list of every imported id that could not be resolved together with its importer. This is Vite's primary 'you forgot to install' surface for the dep optimizer. The throw is at optimizer/index.ts:471.
Source
Thrown at packages/vite/src/node/optimizer/index.ts:471
await fsp.rm(depsCacheDir, { recursive: true, force: true })
}
/**
* Initial optimizeDeps at server start. Perform a fast scan using esbuild to
* find deps to pre-bundle and include user hard-coded dependencies
*/
export function discoverProjectDependencies(environment: ScanEnvironment): {
cancel: () => Promise<void>
result: Promise<Record<string, string>>
} {
const { cancel, result } = scanImports(environment)
return {
cancel,
result: result.then(({ deps, missing }) => {
const missingIds = Object.keys(missing)
if (missingIds.length) {
throw new Error(
`The following dependencies are imported but could not be resolved:\n\n ${missingIds
.map(
(id) =>
`${colors.cyan(id)} ${colors.white(
colors.dim(`(imported by ${missing[id]})`),
)}`,
)
.join(`\n `)}\n\nAre they installed?`,
)
}
return deps
}),
}
}
export function toDiscoveredDependencies(
environment: Environment,View on GitHub (pinned to 89620f09af)
Solutions
- Install the missing package(s): `npm i <pkg>` (or pnpm/yarn equivalent) — the error names each id.
- Fix the import specifier spelling/casing to match the package's `name` or `exports`.
- In monorepos, ensure the dep is in the importing workspace's `package.json` (not just the root) or fix hoisting.
- If the import is conditional/optional, guard it with dynamic import or add it to `optimizeDeps.exclude` and resolve it another way.
Example fix
// before — src uses 'lodash-es' but it isn't installed
import { debounce } from 'lodash-es'
// after
// run: npm install lodash-es Defensive patterns
Strategy: validation
Validate before calling
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
function assertInstalled(importedId: string, importerDir: string) {
try { require.resolve(importedId, { paths: [importerDir] }) }
catch { throw new Error(`Dependency '${importedId}' is imported but not installed. Run: npm i ${importedId}`) }
} Prevention
- Run `npm ls` / `pnpm why` after pulls to catch missing deps.
- In monorepos, declare deps in the consuming workspace, not only the root.
- Add a CI step that fails if `vite optimize` reports unresolved imports.
When it happens
Trigger: Source code (or a dep) imports a package id that is not resolvable from the project — uninstalled, misspelled, hoisted incorrectly in a monorepo, or missing from `exports`/package.json.
Common situations: Forgot `npm install` after pulling; typo in an import specifier; monorepo hoisting hiding a dep from a workspace; a package's `exports` map doesn't expose the subpath used; case-sensitivity mismatch on case-insensitive filesystems.
Related errors
- Could not resolve "${peerDep}" imported by "${parentDep}". I
- Unable to parse: ${filePath}.
- Failed to resolve ${JSON.stringify(id)}. This package is ESM
- Can not commit a Deps Optimization run as it was cancelled
- The build was canceled
AI-assisted analysis of vitejs/vite@89620f09af (2026-08-03).
Data as JSON: /data/errors/37e83703d455cfe0.json.
Report an issue: GitHub.