{"id":"37e83703d455cfe0","repo":"vitejs/vite","slug":"the-following-dependencies-are-imported-but-could","errorCode":null,"errorMessage":"The following dependencies are imported but could not be resolved:\n\n  ${missingIds.map(...).join(`\\n  `)}\n\nAre they installed?","messagePattern":"The following dependencies are imported but could not be resolved:\n\n  (.+?)\n\nAre they installed\\?","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/optimizer/index.ts","lineNumber":471,"sourceCode":"  await fsp.rm(depsCacheDir, { recursive: true, force: true })\n}\n\n/**\n * Initial optimizeDeps at server start. Perform a fast scan using esbuild to\n * find deps to pre-bundle and include user hard-coded dependencies\n */\nexport function discoverProjectDependencies(environment: ScanEnvironment): {\n  cancel: () => Promise<void>\n  result: Promise<Record<string, string>>\n} {\n  const { cancel, result } = scanImports(environment)\n\n  return {\n    cancel,\n    result: result.then(({ deps, missing }) => {\n      const missingIds = Object.keys(missing)\n      if (missingIds.length) {\n        throw new Error(\n          `The following dependencies are imported but could not be resolved:\\n\\n  ${missingIds\n            .map(\n              (id) =>\n                `${colors.cyan(id)} ${colors.white(\n                  colors.dim(`(imported by ${missing[id]})`),\n                )}`,\n            )\n            .join(`\\n  `)}\\n\\nAre they installed?`,\n        )\n      }\n\n      return deps\n    }),\n  }\n}\n\nexport function toDiscoveredDependencies(\n  environment: Environment,","sourceCodeStart":453,"sourceCodeEnd":489,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/src/node/optimizer/index.ts#L453-L489","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before — src uses 'lodash-es' but it isn't installed\nimport { debounce } from 'lodash-es'\n\n// after\n// run:  npm install lodash-es","handlingStrategy":"validation","validationCode":"import { createRequire } from 'node:module'\nconst require = createRequire(import.meta.url)\nfunction assertInstalled(importedId: string, importerDir: string) {\n  try { require.resolve(importedId, { paths: [importerDir] }) }\n  catch { throw new Error(`Dependency '${importedId}' is imported but not installed. Run: npm i ${importedId}`) }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["optimizer","resolution","dependencies","install"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}