cypress-io/cypress · error · Error

Could not find "vite" in your project's dependencies. Please

Error message

Could not find "vite" in your project's dependencies. Please install "vite" to fix this error.\n\n${err}

What it means

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.

Source

Thrown at npm/vite-dev-server/src/getVite.ts:92

      // if the ESM build import fails, try to import the CJS build
      debug('importing vite as ESM failed:', err)
      debug('importing vite as CJS')
      // Vite 4-6 both include the CJS distribution of Vite
      const cjsViteImportPath = path.resolve(vitePackageJsonPath, '../', cjsPath)

      debug('resolved cjsViteImportPath as %s', cjsViteImportPath)

      const viteImport = await import(`${filePrefix}${cjsViteImportPath}`)

      return viteImport.default
    }
  } catch (err) {
    if (err instanceof CJSNotSupportedError) {
      throw err
    }

    throw new Error(`Could not find "vite" in your project's dependencies. Please install "vite" to fix this error.\n\n${err}`)
  }
}

View on GitHub (pinned to 0d85fdc912)

Solutions

  1. Install Vite in the project Cypress is testing: `npm install -D vite` (vite 5, 6, 7, or 8).
  2. Ensure vite resolves from the same projectRoot Cypress uses (cypressConfig.projectRoot).
  3. If using a monorepo, make sure vite is a dependency of the workspace Cypress runs in, not only a sibling.
  4. Read the appended `${err}` to diagnose non-MODULE_NOT_FOUND causes (e.g. corrupt package.json).

Example fix

// before: devServer requests vite but vite is not installed
devServer: { bundler: 'vite' }
// after
npm install -D vite@7
devServer: { bundler: 'vite' }
Defensive patterns

Strategy: validation

Validate before calling

import { createRequire } from 'module'
function ensureViteInstalled(projectRoot: string) {
  const r = createRequire(import.meta.url)
  try { r.resolve('vite/package.json', { paths: [projectRoot] }) }
  catch { throw new Error('Run `npm install -D vite` before starting CT') }
}

Type guard

const isViteResolvable = (projectRoot: string): boolean => { try { createRequire(import.meta.url).resolve('vite/package.json', { paths: [projectRoot] }); return true } catch { return false } }

Try / catch

try { await getVite(config) } catch (e) { if (/Could not find "vite"/.test(e.message)) { /* npm install vite, retry */ } else throw e }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of cypress-io/cypress@0d85fdc912 (2026-08-12). Data as JSON: /api/errors/c5ead670c2dbc049. Report an issue: GitHub.