Documentation Index
Fetch the complete documentation index at: https://next-safe-env.dev/llms.txt
Use this file to discover all available pages before exploring further.
next-safe-env works in Vite projects through its vite adapter, which enforces the VITE_ prefix on all client schema keys and reads client variables from import.meta.env instead of process.env. You get the same typed, validated env object you would in a Next.js app - the adapter handles the differences in how Vite exposes variables to the browser bundle.
Create your env file
Create src/env.ts
Define your server and client schemas. All client keys must be prefixed with
VITE_. In runtimeEnv, use import.meta.env for client variables and process.env for server variables.VITE_ prefix enforcement
The vite adapter checks every key in your client schema before validation runs. If any key does not start with VITE_, the adapter throws immediately:
VITE_ prefix to the browser bundle. Any client variable without the prefix would be silently undefined at runtime - next-safe-env turns that silent failure into a loud startup error.
Auto-detection
If you omitadapter: 'vite' but any of your client schema keys start with VITE_, next-safe-env detects this and selects the vite adapter automatically. You will see a console warning prompting you to set the adapter explicitly:
adapter: 'vite' to your config to suppress the warning and make the intent clear.
Use
import.meta.env.VITE_* in runtimeEnv for client variables and process.env.* for server variables. Vite statically replaces import.meta.env.VITE_* references at build time, which is how it keeps those values out of the server bundle and vice versa.
