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
Neto17mo ago
drizzle does not support esm modules you can use something like dotenv for now or use bunx to execute the push command
Trevor
Trevor17mo 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
Neto17mo ago
you can console.log the process.env before the createEnv and check that are the values
Trevor
Trevor17mo 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
Trevor17mo 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
Neto17mo 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
Trevor17mo ago
sorry that was badly misleading, i did already fix that
Neto
Neto17mo ago
uh try log before the createEnv
Trevor
Trevor17mo 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
Neto17mo ago
something like this
Trevor
Trevor17mo ago
gotcha yeah they're all in there
Trevor
Trevor17mo ago
e.g.:
Neto
Neto17mo ago
can you paste the current env.ts filew
Trevor
Trevor17mo 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
Neto17mo ago
here NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: process.env.NEXT_PUBLIC_PUBLISHABLE_KEY, both sides do not match
Solution
Neto
Neto17mo ago
try with (its missing the CLERK) NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY,
Trevor
Trevor17mo ago
o. m. g. 🤦‍♂️
Neto
Neto17mo ago
t3ggSip
Trevor
Trevor17mo ago
lmao, thank you so much, it turns out i am dumb
Neto
Neto17mo ago
hahahah its fine
Trevor
Trevor17mo 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
Neto17mo ago
i had the esm issue today hahahha
Trevor
Trevor17mo ago
so maybe this will be useful if someone else comes along that
Neto
Neto17mo ago
i found out about the bunx by accident
Trevor
Trevor17mo ago
not all heroes wear capes nyx really appreciate your help thanks : D
Neto
Neto17mo ago
glad to help
Want results from more Discord servers?
Add your server