Env variables not working in Server components
Unanswered
Peterbald posted this in #help-forum
PeterbaldOP
In my nextjs app, the environment variables work only in client components, but not in server components and server actions. Note that the variables work when I run the build task locally, but not when I host on vercel.
const url =
I define the env variables in the vercel dashboard
const url =
${process.env.NEXT_PUBLIC_BACK_URL}/conversations; when called in server components doesnot read the env variable. How to solve this?I define the env variables in the vercel dashboard
3 Replies
@Peterbald In my nextjs app, the environment variables work only in client components, but not in server components and server actions. Note that the variables work when I run the build task locally, but not when I host on vercel.
const url = `${process.env.NEXT_PUBLIC_BACK_URL}/conversations`; when called in server components doesnot read the env variable. How to solve this?
I define the env variables in the vercel dashboard
Lilac
well, env variables are avalaible node js development mode but if you deploy your project on vercel then you have to also give all env varibales when deploying -- past and copy then vercel willl make them avalaible when ever some components try to access them.
got it?
Cuvier’s Dwarf Caiman
Also consider setting them in your next.config.ts