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

  1. Install the missing package(s): `npm i <pkg>` (or pnpm/yarn equivalent) — the error names each id.
  2. Fix the import specifier spelling/casing to match the package's `name` or `exports`.
  3. In monorepos, ensure the dep is in the importing workspace's `package.json` (not just the root) or fix hoisting.
  4. 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

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


AI-assisted analysis of vitejs/vite@89620f09af (2026-08-03). Data as JSON: /data/errors/37e83703d455cfe0.json. Report an issue: GitHub.