Set server side env variable to config object
Answered
Northeast Congo Lion posted this in #help-forum
Northeast Congo LionOP
Answered by Northeast Congo Lion
ill restart IDE to double check
P.S: i did try that before too
P.S: i did try that before too
64 Replies
@Northeast Congo Lion Click to see attachment
if u tend to use this variable only on the clientside u can use NEXTPUBLIC prefix
NEXT_PUBLIC_YOUR_ENV
Northeast Congo LionOP
i use it on server side
and on client?
Northeast Congo LionOP
i used to, but not anymore
if u dont import the env anywhere with the "use client" directive u should be ok
Northeast Congo LionOP
but its not
can u just search for the env?
Northeast Congo LionOP
wym?
search for STRIPE_PREMIUM_MONTHLY_PLAN_ID
Northeast Congo LionOP
acces that env.STRIPE.... directly in server component? yes i could. I mostly want to figure out why im getting this error
also if you put
import "server-only" in this file, it should error on the client usages (assuming you also install that package made by react)@Northeast Congo Lion Click to see attachment
uhm and env.js is some outside script?
nothing to do with nextjs right?
@gin uhm and env.js is some outside script?
Northeast Congo LionOP
from t3 app
uhm
i get it its cooler to have something that automatically switches from prod to dev envs
maybe this is somehow causing the issue idk
@riský also if you put `import "server-only"` in this file, it should error on the client usages (assuming you also install that package made by react)
Northeast Congo LionOP
import "server-only"
add that line to component that importans that config object with env.STRIPE, r? same error
add that line to component that importans that config object with env.STRIPE, r? same error
and subscription.ts is really the only file that is importing your const right?
double check
to the file where u defined your const
@gin double check
Northeast Congo LionOP
yes
Northeast Congo LionOP
no errors
but im not even importing that function that uses that config
whats premiumPlan?
isnt it your const with the env
Northeast Congo LionOP
yeah
So you are using it
so its a issue from this lib
@gin So you are using it
Northeast Congo LionOP
im not importing that function that uses it
You are importing premiumPlan in your file tho
Northeast Congo LionOP
another place where im accessing server env but it works fine
so the compiler executes the logic inside the const
@gin You are importing premiumPlan in your file tho
Northeast Congo LionOP
lemme remove the imports and check it with env.St..
weird, now it works with that..
Northeast Congo LionOP
ill restart IDE to double check
P.S: i did try that before too
P.S: i did try that before too
Answer
@Northeast Congo Lion weird, now it works with that..
what works? directly using env. without your config?
in your "use server" file
Northeast Congo LionOP
no, the very first implementation i used to have error with
good
i was thinking u probably didnt refresh or recompile or whatever
@gin i was thinking u probably didnt refresh or recompile or whatever
Northeast Congo LionOP
i did restart ts
and dev
yeah it works now
thanks for helping me
nice
no problem!
Northeast Congo LionOP
gl !
Northeast Congo LionOP
i dont even know what the solution was
error just disapeared
error just disapeared