import.meta.env.VITE_... is undefined (Vite, Lovable, Bolt)
import.meta.env.VITE_API_URL is undefined
In short: Vite only exposes variables that start with VITE_ to client code, via import.meta.env, not process.env.
Why it happens
Vite apps (Lovable and Bolt projects are typically Vite) don't have process.env in the browser. Variables without the VITE_ prefix are deliberately hidden from the client bundle. Values are inlined at build time.
How to fix it
- Rename the variable to start with
VITE_in.env(for exampleVITE_API_URL). - Read it as
import.meta.env.VITE_API_URL. Replace anyprocess.envreferences in client code. - Restart the dev server after editing
.env. - On your host, set the same variable and rebuild.
- For TypeScript autocomplete, declare it in
src/vite-env.d.tsunderImportMetaEnv.
Copy-paste fix prompt
I'm getting this error in my app: import.meta.env.VITE_API_URL is undefined [Paste the full error, stack trace, and the file it points to here] Likely cause: Vite only exposes variables that start with VITE_ to client code, via import.meta.env, not process.env. Task: Replace process.env usage in client code with import.meta.env, make sure each public variable has the VITE_ prefix, and move any secret-key usage to a server or edge function. Rules: - First explain the root cause in 2 sentences and list the files you'll change. - Make the smallest change that fixes it. Don't refactor unrelated code. - Don't disable security or checks (RLS, auth, signature verification, type checking, CORS allow-all) to make the error disappear. - Never print or hard-code secret keys. - Finish by telling me exactly how to verify the fix.
Common with: Lovable, Bolt, Cursor. Last reviewed 2026-11-13.