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
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:
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:Jump to solution
try with (its missing the CLERK)
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY,
...27 Replies
drizzle does not support esm modules
you can use something like dotenv for now
or use
bunx
to execute the push commandrunning the command with
bunx
didn't solve the problem but interestingly the error output is slightly different
this time it only shows this oneyou can console.log the process.env before the createEnv
and check that are the values
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.
This is the .env.local file btw, obviously with the sensitive values taken out, not sure if that helps
i got the error
on the .env is
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
and on the createEnv is NEXT_PUBLIC_PUBLISHABLE_KEY
@trevor1333sorry
that was badly misleading, i did already fix that
uh
try log before the createEnv
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
?something like this
gotcha
yeah they're all in there
e.g.:
can you paste the current env.ts filew
here
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: process.env.NEXT_PUBLIC_PUBLISHABLE_KEY,
both sides do not matchSolution
try with (its missing the CLERK)
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY,
o.
m.
g.
🤦♂️
lmao, thank you so much, it turns out i am dumb
hahahah
its fine
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
i had the esm issue today
hahahha
so maybe this will be useful if someone else comes along that
i found out about the bunx by accident
not all heroes wear capes nyx
really appreciate your help thanks : D
glad to help