{"record":{"id":"e7abade38edc33f5","repo":"cypress-io/cypress","slug":"cjs-builds-of-vite-majorversionnumber-are-not-s","errorCode":null,"errorMessage":"CJS builds of vite ${majorVersionNumber} are not supported","messagePattern":"CJS builds of vite (.+?) are not supported","errorType":"exception","errorClass":"CJSNotSupportedError","httpStatus":null,"severity":"error","filePath":"npm/vite-dev-server/src/getVite.ts","lineNumber":72,"sourceCode":"      esmPath = viteExports.import\n      cjsPath = viteExports.require\n    }\n\n    debug('vite ESM build path: %s', esmPath)\n    debug('vite CJS build path: %s', cjsPath)\n\n    try {\n      // try to import the ESM build of Vite\n      const esmViteImportPath = path.resolve(vitePackageJsonPath, '../', esmPath)\n\n      debug('resolved esmViteImportPath as %s', esmViteImportPath)\n\n      const viteImport = await import(`${filePrefix}${esmViteImportPath}`)\n\n      return viteImport\n    } catch (err) {\n      if (majorVersionNumber >= 7) {\n        throw new CJSNotSupportedError(`CJS builds of vite ${majorVersionNumber} are not supported`)\n      }\n\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    }","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/cypress-io/cypress/blob/0d85fdc91230885bca0a91df278312800a48b727/npm/vite-dev-server/src/getVite.ts#L54-L90","documentation":"Thrown as CJSNotSupportedError by getVite when the ESM import of Vite fails AND the detected Vite major is >= 7. Vite 7 removed its CommonJS build entirely, so the previous fallback (import the CJS build, used for Vite 4–6) no longer exists. The error signals that the only supported Vite build (ESM) could not be imported and there is no CJS alternative to retry.","triggerScenarios":"getVite resolves vite/package.json, finds majorVersionNumber >= 7, attempts `import(esmViteImportPath)` and it throws — then rethrows as CJSNotSupportedError. Typical causes: the ESM entry path is wrong/corrupted, the Vite install is incomplete, a transpiler/runner strips dynamic ESM import, or the project's Node version cannot load Vite 7's ESM.","commonSituations":"Upgrading to Vite 7 in an environment that mangles ESM (older Jest config, ts-node with CommonJS module setting, a bundler that rewrites import()); a partial/corrupted vite install; running under a Node version below Vite 7's requirement.","solutions":["Use Node 20.19+ or 22+ (Vite 7's minimum) and ensure the project's package.json is not forcing CommonJS where Vite's ESM must load.","Reinstall Vite cleanly: `npm install vite@7` to restore a complete ESM build.","Remove any ts-node/babel rewrites that transform dynamic `import()` into require() for the Vite path.","If your toolchain cannot load ESM, stay on Vite 6 which still ships a CJS fallback."],"exampleFix":"// before: project forces CJS, breaks vite 7 ESM\n// package.json\n{ \"type\": \"commonjs\" }\n// after\n{ \"type\": \"module\" }  // or downgrade to vite@6","handlingStrategy":"validation","validationCode":"import gte from 'semver/functions/gte.js'\nimport { createRequire } from 'module'\nconst r = createRequire(import.meta.url)\nconst v = r('vite/package.json').version\nif (gte(v, '7.0.0') && process.version.startsWith('v18')) throw new Error('Node 20+ required for Vite 7')","typeGuard":"const supportsVite7Esm = (): boolean => Number(process.versions.node.split('.')[0]) >= 20","tryCatchPattern":"try { vite = await getVite(config) } catch (e) { if (e instanceof CJSNotSupportedError || /CJS builds of vite/.test(e.message)) { /* use vite@6 fallback */ } else throw e }","preventionTips":["Use Node 20.19+/22+ when adopting Vite 7.","Avoid forcing CommonJS module resolution where Vite ESM loads.","Keep a Vite 6 fallback in CI until your toolchain is ESM-clean."],"tags":["vite","esm","cjs","version-mismatch","dev-server"],"backgroundTag":null,"analyzedSha":"0d85fdc91230885bca0a91df278312800a48b727","analyzedAt":"2026-08-12T16:24:28.056Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}