Skip to main content

vite-env

The env.ts layer for Vite — define once, validate everywhere, import with types.

activeTypeScriptVitenpm2026-04-05

What @t3-oss/env is for Next.js, but built natively on Vite 8 and Rolldown. Define your environment variables once with a schema, and get validated, typed imports everywhere.

Why I Built This

I wrote about the four problems with plain Vite environment variables — no validation, no type safety, string-only values, and easy server/client leaks. This plugin solves all four.

Key Features

  • Typed virtual modules — import env with full IntelliSense
  • Server/client split with build-time leak detection
  • Zod v4 native validation with Standard Schema support (Valibot, ArkType)
  • Auto .d.ts generation for type safety without manual declarations
  • Platform presets for Vercel, Railway, Netlify
  • HMR .env watching — changes reload without restart

Technical Details

The plugin generates virtual modules at build time, splitting server and client variables into separate imports. If client code accidentally imports a server variable, the build fails — preventing secret leaks before they happen.