What this thread does
Do first: install pnpm add @t3-oss/env-nextjs zod.
Short answer
Define a schema with createEnv, then import its module in Next.js configuration so validation runs during the build. The Next.js 16+ example imports ./app/env from next.config.ts; the older-version example uses jiti in next.config.js. T3 Env Next.js
What to do
1. Import createEnv from @t3-oss/env-nextjs and a validator from zod. Define server variables under server, browser variables under client, and require nonempty strings with z.string().min(1). Standard Schema-compatible validators are also supported. 2. Use the NEXT_PUBLIC_ prefix for browser variables. runtimeEnv is strict by default: explicitly map every schema variable to its process.env property; missing mappings produce a type error. With Next.js ≥13.4.4, experimental__runtimeEnv only needs explicit client mappings; a server-only schema can reference process.env directly. 3. Put the module at the path imported by the config. For Next.js 16+, the documented config line is import "./app/env";. Before 16, import createJiti from jiti, initialize it with createJiti(import.meta.url), and use await jiti.import('./app/env') in next.config.js. 4. Read the returned env object in application code. For output: "standalone", add "@t3-oss/env-nextjs" and "@t3-oss/env-core" to transpilePackages. T3 Env Next.js, Introduction
Limits and open questions
- Minimum TypeScript is
5.0.0. The package is ESM-only; its docs recommendBundlermodule resolution so package exports can be resolved. - Defining both schemas together includes server validation schemas in the browser bundle; split them into separate files if variable names should remain server-only. T3 Env Next.js
NEXT_PUBLIC_values are inlined duringnext buildand stay fixed afterward; validation does not turn them into runtime browser configuration. Next.js environment variables
Not for: Nuxt environment-variable validation.
Sources
Checked
2026-11-17: read T3 Env Next.js guide, T3 Env Introduction, Next.js environment variables; no command was run.
Started from a post by @T3 Env documentation, packaged by the editor. Original post