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 Env | zod-config | Notes |
|---|---|---|
createEnv from @t3-oss/env-nextjs | loadEnvConfig from zod-config/nextjs | Prefix fixed to NEXT_PUBLIC_. |
createEnv from @t3-oss/env-core | loadEnvConfig from zod-config | Pass the prefix as clientPrefix. |
server, client, shared | server, client, shared | Unchanged. |
runtimeEnv | runtimeEnv | Works 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: true | Every server, client and shared key must be listed. |
onValidationError | onError | Receives the Zod error rather than the issues array: use error.issues. Throw from it to replace the default error. |
skipValidation | skipValidation | Returns raw values. Reading server variables in the browser still throws. |
import "./src/env" in next.config | The same, or withZodConfigEnv | The wrapper also works with next.config.mjs and path aliases. On Vite, use the zodConfigEnv plugin. |
isServer | isServer | Unchanged. |
import { } from 'zod-config/nextjs';
import { } from 'zod';
export const = ({
: { : .() },
: { : .() },
: {
: ..,
: ..,
},
: () => {
.(.);
},
});