Vite "The CJS build of Vite's Node API is deprecated" warning failing CI
Vite 5+ deprecated the CommonJS build of its Node API. When a vite.config or wrapper script loads Vite via require, Vite prints the deprecation, and pipelines that fail on stderr or that pin an exact log treat it as a failure.
What this error means
The build or a custom script logs "The CJS build of Vite's Node API is deprecated. See https://vite.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details."
The CJS build of Vite's Node API is deprecated. See
https://vite.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.Common causes
A CommonJS config loading Vite via require
A vite.config.js in a CommonJS package, or a script doing const { build } = require('vite'), triggers the deprecated CJS entry.
A tool importing the CJS Vite API
A plugin or wrapper still imports Vite's Node API as CommonJS, so the warning appears even if your own config is ESM.
How to fix it
Switch the package and config to ESM
- Add
"type": "module"topackage.json(or rename config to.mjs). - Use
importinstead ofrequirefor Vite's API. - Re-run the build; the deprecation no longer prints.
// package.json
{ "type": "module" }Import Vite's API as ESM in scripts
Replace the CJS require with an ESM import in any script that drives Vite programmatically.
import { build } from 'vite';
await build();How to prevent it
- Use ESM for Vite config and any scripts that call its Node API.
- Keep Vite plugins current so they import the ESM API.
- Avoid pinning CI on exact log output that includes deprecations.