Next.js Discord

Discord Forum

How do I force NextJS to not cache runtime environment variables?

Answered
Blue-gray Gnatcatcher posted this in #help-forum
Open in Discord
Avatar
Blue-gray GnatcatcherOP
I have a Constants file (https://github.com/Purdue-CS307-tsundoku/tsundoku/blob/main/backend/src/app/Constants.ts) that declares some constants for my app. The values are read from the system environment variables. Unfortunately, it seems like NextJS does away with the entire file and puts undefined for the values during compilation. I've tried using noCache but it still gives me undefined values -- probably because it maybe doesn't work outside of a Component? Is putting export const dynamic = 'force-dynamic' ; the correct solution here?
Answered by Blue-gray Gnatcatcher
I managed to fix it by just moving the system environment variable calls to the constants file itself -- I guess NextJS didn't like that I was going through two levels to fetch the system environment variables. Solved
View full answer

1 Reply

Avatar
Blue-gray GnatcatcherOP
I managed to fix it by just moving the system environment variable calls to the constants file itself -- I guess NextJS didn't like that I was going through two levels to fetch the system environment variables. Solved
Answer