Trevor
Trevor
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Trevor on 7/2/2023 in #questions
env-nextjs not able to find .env variables
At least I think that's what's going on. Here's what I have in env.ts
import { createEnv } from '@t3-oss/env-nextjs';
import { z } from 'zod';

export const env = createEnv({
server: {
CLERK_SECRET_KEY: z.string(),
PLANETSCALE_DB: z.string(),
PLANETSCALE_DB_CERT_PATH: z.string(),
PLANETSCALE_DB_HOST: z.string(),
PLANETSCALE_DB_USERNAME: z.string(),
PLANETSCALE_DB_PASSWORD: z.string(),
PLANETSCALE_DB_URL: z.string(),
},
client: {
NEXT_PUBLIC_CLERK_SIGN_IN_URL: z.string(),
NEXT_PUBLIC_CLERK_SIGN_UP_URL: z.string(),
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL: z.string(),
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: z.string(),
},
// For Next.js >= 13.4.4, you only need to destructure client variables:
experimental__runtimeEnv: {
NEXT_PUBLIC_CLERK_SIGN_IN_URL: process.env.NEXT_PUBLIC_CLERK_SIGN_IN_URL,
NEXT_PUBLIC_CLERK_SIGN_UP_URL: process.env.NEXT_PUBLIC_CLERK_SIGN_UP_URL,
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL: process.env.NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL,
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: process.env.NEXT_PUBLIC_PUBLISHABLE_KEY,
},
});
import { createEnv } from '@t3-oss/env-nextjs';
import { z } from 'zod';

export const env = createEnv({
server: {
CLERK_SECRET_KEY: z.string(),
PLANETSCALE_DB: z.string(),
PLANETSCALE_DB_CERT_PATH: z.string(),
PLANETSCALE_DB_HOST: z.string(),
PLANETSCALE_DB_USERNAME: z.string(),
PLANETSCALE_DB_PASSWORD: z.string(),
PLANETSCALE_DB_URL: z.string(),
},
client: {
NEXT_PUBLIC_CLERK_SIGN_IN_URL: z.string(),
NEXT_PUBLIC_CLERK_SIGN_UP_URL: z.string(),
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL: z.string(),
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: z.string(),
},
// For Next.js >= 13.4.4, you only need to destructure client variables:
experimental__runtimeEnv: {
NEXT_PUBLIC_CLERK_SIGN_IN_URL: process.env.NEXT_PUBLIC_CLERK_SIGN_IN_URL,
NEXT_PUBLIC_CLERK_SIGN_UP_URL: process.env.NEXT_PUBLIC_CLERK_SIGN_UP_URL,
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL: process.env.NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL,
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: process.env.NEXT_PUBLIC_PUBLISHABLE_KEY,
},
});
When I try to run a command that uses one of these variables (drizzle-kit push:mysql) the Zod parse fails and gives me this in the terminal:
❌ Invalid environment variables: {
CLERK_SECRET_KEY: [ 'Required' ],
PLANETSCALE_DB: [ 'Required' ],
PLANETSCALE_DB_CERT_PATH: [ 'Required' ],
PLANETSCALE_DB_HOST: [ 'Required' ],
PLANETSCALE_DB_USERNAME: [ 'Required' ],
PLANETSCALE_DB_PASSWORD: [ 'Required' ],
PLANETSCALE_DB_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_SIGN_IN_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_SIGN_UP_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL: [ 'Required' ],
NEXT_PUBLIC_PUBLISHABLE_KEY: [ 'Required' ]
}
❌ Invalid environment variables: {
CLERK_SECRET_KEY: [ 'Required' ],
PLANETSCALE_DB: [ 'Required' ],
PLANETSCALE_DB_CERT_PATH: [ 'Required' ],
PLANETSCALE_DB_HOST: [ 'Required' ],
PLANETSCALE_DB_USERNAME: [ 'Required' ],
PLANETSCALE_DB_PASSWORD: [ 'Required' ],
PLANETSCALE_DB_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_SIGN_IN_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_SIGN_UP_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL: [ 'Required' ],
NEXT_PUBLIC_PUBLISHABLE_KEY: [ 'Required' ]
}
My env variables are defined at the root of the same directory env.ts is in, .env.local I think this is saying it can't find them? Any help would be appreciated, I'm sure I'm missing something simple <:honk_thonk:753870955234721821>
49 replies