vitejs/vite · critical · Error
The following dependencies are imported but could not be…
Error message
The following dependencies are imported but could not be resolved:
${missingIds mapped to "id (imported by importer)"}
Are they installed? What it means
Thrown by `discoverProjectDependencies` after the dependency scanner (esbuild/rolldown scan of entry HTML/JS) finds imports that resolve to no installed package. Each missing id is listed with its importer so you can locate the offending import. It is a hard stop: dependency optimization cannot proceed with unresolvable bare imports.
Solutions
- Install the listed package: run `npm install <missing-id>` (or pnpm/yarn equivalent) matching the message.
- If the import is intentional but should not be bundled, add it to `optimizeDeps.exclude` or `build.rollupOptions.external`.
- If it is a virtual/conditional import, guard it so the scanner cannot see it, or mark it external.
- For workspaces, re-run the install with workspace linking (`pnpm install`, `npm install --workspaces`) to fix missing hoists.
- Fix typos in the specifier or update the import path to a real subpath that the package exports.
- Clear the Vite cache (`node_modules/.vite`) after fixing installs to drop stale optimization metadata.
Example fix
// before: app.ts imports 'lodash.debounce' but it is not installed import debounce from 'lodash.debounce' // after: install then keep the import // $ npm install lodash.debounce import debounce from 'lodash.debounce'
Defensive patterns
Strategy: validation
Validate before calling
import { createRequire } from 'node:module'
import path from 'node:path'
const require = createRequire(import.meta.url)
function assertResolvable(specifiers: string[], fromDir: string) {
for (const s of specifiers) {
if (!s.startsWith('.') && !path.isAbsolute(s)) {
try { require.resolve(s, { paths: [fromDir] }) }
catch { throw new Error(`Bare import '${s}' is not resolvable from ${fromDir}; install it before build.`) }
}
}
}
// run over your entry source imports pre-build Try / catch
try {
await build()
} catch (e) {
if (e instanceof Error && e.message.startsWith('The following dependencies are imported but could not be resolved')) {
console.error('Missing deps detected. Running install...')
// optionally: execSync('npm install') then retry once
}
throw e
} Prevention
- Always install after switching branches: run `npm ci` (or equivalent) before `vite`/`vite build`.
- Add a CI step that fails if `git diff --name-only` includes package.json without a lockfile change.
- Lint for imports of packages absent from package.json dependencies.
When it happens
Trigger: `scanImports` populates a `missing` map; in index.ts:469 if `Object.keys(missing).length` is non-zero, the error lists each `id (imported by importer)`. Occurs on `vite` / `vite dev` / `vite build` startup when source code imports a bare specifier that node resolution cannot find from the importer's directory.
Common situations: Forgot `npm install` after pulling code or switching branches. Package is in `dependencies` of a sibling workspace but not hoisted/installed in this one. Typo in import specifier. Conditional/optional import that should be excluded via `optimizeDeps.exclude` or externalized. Monorepo with missing symlink after a partial install. Using a package that is `devDependencies` only and running in a prod-only install.
Related errors
- failed to resolve rolldownOptions.input value
- Could not resolve " " imported by " ". Is it installed?
- Failed to load PostCSS config
- Failed to load `transformWithEsbuild`. It is deprecated and…
- No available ports found between
AI-assisted analysis of vitejs/vite@b4d66fee14 (2026-08-11).
Data as JSON: /api/errors/f90ec1fdce1020ff.
Report an issue: GitHub.
Appendix: 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 b4d66fee14)