{"record":{"id":"c5ead670c2dbc049","repo":"cypress-io/cypress","slug":"could-not-find-vite-in-your-project-s-dependenci","errorCode":null,"errorMessage":"Could not find \"vite\" in your project's dependencies. Please install \"vite\" to fix this error.\\n\\n${err}","messagePattern":"Could not find \"vite\" in your project's dependencies\\. Please install \"vite\" to fix this error\\.\\\\n\\\\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"npm/vite-dev-server/src/getVite.ts","lineNumber":92,"sourceCode":"\n      // if the ESM build import fails, try to import the CJS build\n      debug('importing vite as ESM failed:', err)\n      debug('importing vite as CJS')\n      // Vite 4-6 both include the CJS distribution of Vite\n      const cjsViteImportPath = path.resolve(vitePackageJsonPath, '../', cjsPath)\n\n      debug('resolved cjsViteImportPath as %s', cjsViteImportPath)\n\n      const viteImport = await import(`${filePrefix}${cjsViteImportPath}`)\n\n      return viteImport.default\n    }\n  } catch (err) {\n    if (err instanceof CJSNotSupportedError) {\n      throw err\n    }\n\n    throw new Error(`Could not find \"vite\" in your project's dependencies. Please install \"vite\" to fix this error.\\n\\n${err}`)\n  }\n}\n","sourceCodeStart":74,"sourceCodeEnd":95,"githubUrl":"https://github.com/cypress-io/cypress/blob/0d85fdc91230885bca0a91df278312800a48b727/npm/vite-dev-server/src/getVite.ts#L74-L95","documentation":"The outer catch in getVite, reached only for non-CJSNotSupportedError failures anywhere in the function: resolving vite/package.json from projectRoot, reading/parsing its package.json, or importing either build. The message tells the user Vite itself could not be located/resolved and appends the original error for detail. It is the canonical 'vite is not installed' signal for the dev server.","triggerScenarios":"require.resolve('vite/package.json', { paths: [projectRoot] }) throws MODULE_NOT_FOUND (vite not installed), the package.json import/parse fails, or viteExports resolution throws — and none of these is a CJSNotSupportedError. The original error is concatenated into the message.","commonSituations":"Running Cypress component testing with `devServer: { bundler: 'vite' }` in a project that has not installed vite; vite hoisted to a location require.resolve cannot reach from projectRoot; a yarn-workspace structure where vite is in a sibling package; a broken/partial vite install.","solutions":["Install Vite in the project Cypress is testing: `npm install -D vite` (vite 5, 6, 7, or 8).","Ensure vite resolves from the same projectRoot Cypress uses (cypressConfig.projectRoot).","If using a monorepo, make sure vite is a dependency of the workspace Cypress runs in, not only a sibling.","Read the appended `${err}` to diagnose non-MODULE_NOT_FOUND causes (e.g. corrupt package.json)."],"exampleFix":"// before: devServer requests vite but vite is not installed\ndevServer: { bundler: 'vite' }\n// after\nnpm install -D vite@7\ndevServer: { bundler: 'vite' }","handlingStrategy":"validation","validationCode":"import { createRequire } from 'module'\nfunction ensureViteInstalled(projectRoot: string) {\n  const r = createRequire(import.meta.url)\n  try { r.resolve('vite/package.json', { paths: [projectRoot] }) }\n  catch { throw new Error('Run `npm install -D vite` before starting CT') }\n}","typeGuard":"const isViteResolvable = (projectRoot: string): boolean => { try { createRequire(import.meta.url).resolve('vite/package.json', { paths: [projectRoot] }); return true } catch { return false } }","tryCatchPattern":"try { await getVite(config) } catch (e) { if (/Could not find \"vite\"/.test(e.message)) { /* npm install vite, retry */ } else throw e }","preventionTips":["Declare vite as a devDependency in the workspace Cypress runs in.","In monorepos, ensure vite resolves from cypressConfig.projectRoot.","Add a preflight check that resolves vite/package.json before launching CT."],"tags":["vite","dependency","module-not-found","dev-server"],"backgroundTag":null,"analyzedSha":"0d85fdc91230885bca0a91df278312800a48b727","analyzedAt":"2026-08-12T16:24:28.056Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}