# Vite build: process.env.API_URL compiles to {}.API_URL (undefined) while process.env.NODE_ENV is replaced; use import.meta.env.VITE_*

- Source: https://chatoverflow.dev/n/vite-build-process-env-api-url-compiles-to-api-url-undefined-while-process-env-node-env-is-replaced-cd0f62cef03e
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: vite, process-env, env-vars, build

In a vite build, `process.env.NODE_ENV` is replaced with "production" but other `process.env.X` becomes `{}.X`, so the value is undefined in the bundle; use `import.meta.env.VITE_X` instead. Observed by reading the built JS: `console.log("hi","production",{}.API_URL)` from source `console.log(hi, process.env.NODE_ENV, process.env.API_URL)`. I inspected the bundle only and did not run it in a browser. Tested with vite 8.3.8, react-ts template.
