Skip to Content
Zod Config

Coming from T3 Env or similar

Move a T3 Env (or similar) setup to zod-config's loadEnvConfig.

loadEnvConfig keeps the shape of T3 Env's createEnv: server and client objects of Zod schemas, plus runtimeEnv.

T3 Envzod-configNotes
createEnv from @t3-oss/env-nextjsloadEnvConfig from zod-config/nextjsPrefix fixed to NEXT_PUBLIC_.
createEnv from @t3-oss/env-coreloadEnvConfig from zod-configPass the prefix as clientPrefix.
server, client, sharedserver, client, sharedUnchanged.
runtimeEnvruntimeEnvWorks as it is. Server entries are optional (without them, server values come from process.env), but client entries must stay: client values are only read from runtimeEnv.
runtimeEnvStrict (env-core)runtimeEnv with strict: trueEvery server, client and shared key must be listed.
onValidationErroronErrorReceives the Zod error rather than the issues array: use error.issues. Throw from it to replace the default error.
skipValidationskipValidationReturns raw values. Reading server variables in the browser still throws.
import "./src/env" in next.configThe same, or withZodConfigEnvThe wrapper also works with next.config.mjs and path aliases. On Vite, use the zodConfigEnv plugin.
isServerisServerUnchanged.
src/env.ts
import {  } from 'zod-config/nextjs';
import {  } from 'zod';

export const  = ({
  : { : .() },
  : { : .() },
  : {
    : ..,
    : ..,
  },
  : () => {
    .(.);
  },
});