Vite "The CJS build of Vite's Node API is deprecated" Warning
Vite emits this warning when its Node API is loaded through the deprecated CommonJS build - typically because your config or tooling require()s Vite instead of importing it as ESM. It is a warning, but strict CI can treat it as noise that masks failures or be configured to fail on it.
What this error means
Running vite or a script that imports Vite prints The CJS build of Vite's Node API is deprecated. It is harmless on its own but signals that your config/tooling is on the wrong module path, and the CJS API will be removed in a future major.
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
Config or tooling requires Vite via CommonJS
A vite.config.js without "type": "module", or a custom script doing const { build } = require('vite'), loads Vite's deprecated CJS Node API.
Package not marked as ESM
The project package.json lacks "type": "module", so .js config files are treated as CommonJS and Node picks Vite's CJS entry.
How to fix it
Make the package ESM
Set the module type so config files load as ESM and Vite uses its ESM Node API.
// package.json
{ "type": "module" }Import Vite instead of requiring it
In any script using Vite's Node API, use ESM imports.
// scripts/build.mjs
import { build } from 'vite'
await build()How to prevent it
- Use ESM (
"type": "module") for projects on modern Vite. - Author config as
vite.config.ts/.mjsand import the Node API, neverrequireit. - Update custom build scripts to ESM ahead of the CJS API removal.