Vite "process is not defined" in the browser build in CI
Vite targets the browser and does not inject a Node process global. Code (often a dependency) reads process.env.NODE_ENV directly, so the built bundle throws process is not defined when it runs.
What this error means
The build succeeds but the app or a headless test in CI throws "Uncaught ReferenceError: process is not defined", or a prerender step crashes on the same reference.
Uncaught ReferenceError: process is not defined
at node_modules/some-lib/index.js:1:1Common causes
Code reads process.env directly in browser code
Vite exposes env via import.meta.env, not process.env. A direct process.env reference has no value in the browser bundle.
A dependency assumes a Node environment
A library written for Node references process at module load, and Vite does not shim it for the browser.
How to fix it
Use import.meta.env for your own code
Read Vite environment variables through import.meta.env instead of process.env.
// before: process.env.NODE_ENV
const mode = import.meta.env.MODEDefine the global for a dependency that needs it
When a dependency hard-requires process.env, define the specific values at build time.
export default {
define: { 'process.env.NODE_ENV': JSON.stringify('production') }
}How to prevent it
- Use
import.meta.envfor env in browser code. - Audit dependencies that assume Node globals before bundling for the browser.
- Avoid blanket
defineof all ofprocess.env; define only what is needed.