Closed rishabhchauhan421 closed 6 months ago
i don't know when next.js loads these into the environment so perhaps your best bet is to set them as shared variables in env.ts
instead?
// env.ts
import { createEnv } from '@t3-oss/env-nextjs';
import { z } from 'zod';
export const env = createEnv({
server: {
DATABASE_URL: z.string().url(),
},
client: {
NEXT_PUBLIC_BASE_URL: z.string().url(),
},
shared: {
siteName: z.string(),
},
runtimeEnv: {
DATABASE_URL: process.env.DATABASE_URL,
siteName: "The Custom Crow",
},
});
Resolved:
inside env.ts
export const env = createEnv({
server: {
DATABASE_URL: z.string().url(),
},
client: {
NEXT_PUBLIC_BASE_URL: z.string().url(),
NEXT_PUBLIC_siteName: z.string().min(1),
NEXT_PUBLIC_facebookUrl: z.string().min(1),
NEXT_PUBLIC_twitterUrl: z.string().min(1),
},
runtimeEnv: {
// From .env file
DATABASE_URL: process.env.DATABASE_URL,
// From next.config.js, but it is showing error here
NEXT_PUBLIC_siteName: process.env.siteName,
NEXT_PUBLIC_facebookUrl: process.env.facebookUrl,
NEXT_PUBLIC_twitterUrl: process.env.twitterUrl,
},
});
Hi, I want typesafe my environment variable which is correctly working for .env file. But I have saved some env variables inside next.config.js also. How can I typesafe my next.config.js env variable also.
next.config.js file
env.ts file