env variable fails for enum type

/**
* Specify your client-side environment variables schema here.
* This way you can ensure the app isn't built with invalid env vars.
* To expose them to the client, prefix them with `NEXT_PUBLIC_`.
*/
export const clientSchema = z.object({
NEXT_PUBLIC_APP_URL: z.string(),
NEXT_PUBLIC_AWS_S3_BUCKET_NAME: z.string(),
NEXT_PUBLIC_EMAIL_VERIFICATION: z
.enum(["OPTIONAL", "REQUIRED"])
.default("OPTIONAL"),
});

/**
* You can't destruct `process.env` as a regular object, so you have to do
* it manually here. This is because Next.js evaluates this at build time,
* and only used environment variables are included in the build.
* @type {{ [k in keyof z.infer<typeof clientSchema>]: z.infer<typeof clientSchema>[k] | undefined }}
*/
export const clientEnv = {
NEXT_PUBLIC_APP_URL: process.env.NEXT_PUBLIC_APP_URL,
NEXT_PUBLIC_AWS_S3_BUCKET_NAME: process.env.NEXT_PUBLIC_AWS_S3_BUCKET_NAME,
NEXT_PUBLIC_EMAIL_VERIFICATION: process.env.NEXT_PUBLIC_EMAIL_VERIFICATION,
};
/**
* Specify your client-side environment variables schema here.
* This way you can ensure the app isn't built with invalid env vars.
* To expose them to the client, prefix them with `NEXT_PUBLIC_`.
*/
export const clientSchema = z.object({
NEXT_PUBLIC_APP_URL: z.string(),
NEXT_PUBLIC_AWS_S3_BUCKET_NAME: z.string(),
NEXT_PUBLIC_EMAIL_VERIFICATION: z
.enum(["OPTIONAL", "REQUIRED"])
.default("OPTIONAL"),
});

/**
* You can't destruct `process.env` as a regular object, so you have to do
* it manually here. This is because Next.js evaluates this at build time,
* and only used environment variables are included in the build.
* @type {{ [k in keyof z.infer<typeof clientSchema>]: z.infer<typeof clientSchema>[k] | undefined }}
*/
export const clientEnv = {
NEXT_PUBLIC_APP_URL: process.env.NEXT_PUBLIC_APP_URL,
NEXT_PUBLIC_AWS_S3_BUCKET_NAME: process.env.NEXT_PUBLIC_AWS_S3_BUCKET_NAME,
NEXT_PUBLIC_EMAIL_VERIFICATION: process.env.NEXT_PUBLIC_EMAIL_VERIFICATION,
};
1 Reply
shikishikichangchang
ERROR: Type 'string | undefined' is not assignable to type '"OPTIONAL" | "REQUIRED" | undefined'. Type 'string' is not assignable to type '"OPTIONAL" | "REQUIRED" | undefined'.t I used z.enum to ensure that the variables need to be one of those but it seems like when an env variable is imported, it's always import as string
Want results from more Discord servers?
Add your server