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>
Solution:
try with (its missing the CLERK) NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY,...
Jump to solution
27 Replies
Neto
Neto2y ago
drizzle does not support esm modules you can use something like dotenv for now or use bunx to execute the push command
Trevor
TrevorOP2y ago
running the command with bunx didn't solve the problem but interestingly the error output is slightly different
❌ Invalid environment variables: { NEXT_PUBLIC_PUBLISHABLE_KEY: [ 'Required' ] }
❌ Invalid environment variables: { NEXT_PUBLIC_PUBLISHABLE_KEY: [ 'Required' ] }
this time it only shows this one
Neto
Neto2y ago
you can console.log the process.env before the createEnv and check that are the values
Trevor
TrevorOP2y ago
That's an interesting idea but i'm not sure how I can do that. I tried to log them out in the client on load but the app crashes because it thinks the env variables are invalid before the log runs.
Trevor
TrevorOP2y ago
CLERK_SECRET_KEY=***

NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=***
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/

PLANETSCALE_DB=***
PLANETSCALE_DB_CERT_PATH=***

PLANETSCALE_DB_HOST=***
PLANETSCALE_DB_USERNAME=***
PLANETSCALE_DB_PASSWORD=***

PLANETSCALE_DB_URL=***
CLERK_SECRET_KEY=***

NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=***
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/

PLANETSCALE_DB=***
PLANETSCALE_DB_CERT_PATH=***

PLANETSCALE_DB_HOST=***
PLANETSCALE_DB_USERNAME=***
PLANETSCALE_DB_PASSWORD=***

PLANETSCALE_DB_URL=***
This is the .env.local file btw, obviously with the sensitive values taken out, not sure if that helps
Neto
Neto2y ago
i got the error on the .env is NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY and on the createEnv is NEXT_PUBLIC_PUBLISHABLE_KEY @trevor1333
Trevor
TrevorOP2y ago
sorry that was badly misleading, i did already fix that
Neto
Neto2y ago
uh try log before the createEnv
Trevor
TrevorOP2y ago
good eye though lol, sorry i let you bark up that tree, lemme edit that message I'm not sure what you mean by this, you mean in the env.ts file where i'm invoking createEnv?
Neto
Neto2y ago
something like this
Trevor
TrevorOP2y ago
gotcha yeah they're all in there
Trevor
TrevorOP2y ago
e.g.:
Neto
Neto2y ago
can you paste the current env.ts filew
Trevor
TrevorOP2y ago
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,
},
});
Neto
Neto2y ago
here NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: process.env.NEXT_PUBLIC_PUBLISHABLE_KEY, both sides do not match
Solution
Neto
Neto2y ago
try with (its missing the CLERK) NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY,
Trevor
TrevorOP2y ago
o. m. g. 🤦‍♂️
Neto
Neto2y ago
t3ggSip
Trevor
TrevorOP2y ago
lmao, thank you so much, it turns out i am dumb
Neto
Neto2y ago
hahahah its fine
Trevor
TrevorOP2y ago
i shall leave this question up so that future generations can witness my shame btw you were also right that i needed to run the command with bunx
Neto
Neto2y ago
i had the esm issue today hahahha
Trevor
TrevorOP2y ago
so maybe this will be useful if someone else comes along that
Neto
Neto2y ago
i found out about the bunx by accident
Trevor
TrevorOP2y ago
not all heroes wear capes nyx really appreciate your help thanks : D
Neto
Neto2y ago
glad to help
Want results from more Discord servers?
Add your server