Skip to content
Latchkey

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."

vite
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

  1. Add "type": "module" to package.json (or rename config to .mjs).
  2. Use import instead of require for Vite's API.
  3. Re-run the build; the deprecation no longer prints.
package.json
// 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.

scripts/build.mjs
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.

Frequently asked questions

What causes ""CJS build of Vite's Node API is deprecated""?
A vite.config.js in a CommonJS package, or a script doing const { build } = require('vite'), triggers the deprecated CJS entry.
How do I fix "CJS build of Vite's Node API is deprecated"?
Switch the package and config to ESM

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card