env Variables causing issue deploying to Vercel
Howdy! So I'm trying to host my CT3A on vercel. The build is failing, looks like it's the env variables that are causing the issue but I'm not sure what I'm doing wrong.
I double checked that my schema.mjs file isn't missing any variables, and I actually did miss one, so I figured sure that must be it, but even after adding it to the repo, the build is failing for the same reason.
This is my schema.mjs
And my build error is attached. I tried adding the NODE_ENV even though it's my understanding I shouldn't need to add that, it's inferred by default, still the same error.
Any ideas?
7 Replies
hey, maybe try without quotes first? not sure what else it could be
just tried no quotes, no luck
sorry i was a bit distracted and i missed the error, you need to split your schema into 2: server and client
and then use
since
NEXT_PUBLIC_
prefixed environment variable are client side ones not serverSo is the NEXT_PUBLIC going to need to live in a separate .env file then? And when I add the env variables to vercel, am I going to need to differentiate them at all? Thanks for the help btw!
a single .env file is enough, just make sure to prefix environment variable that are used inside you pages/components with
NEXT_PUBLIC_
and also separate them within your schema.mjs fileOk ya I finally managed to get it working by putting the NEXT_PUBLIC_ADMIN into the clientSchema, thanks for the catch! So any schema that I'm using client side needs to live in the cleintEnv I'm guessing?
exactly, when you have to use a new var, it always goes in the same .env, but then you check if it's used by a page/component and make sure it is BOTH prefixed with NEXT_PUBLIC and inside your clientSchema. But if it a server env, just it goes in the server schema
this separation is used because if you mess up, your pages/components cannot read server env and will cause hydration errors