How do I force NextJS to not cache runtime environment variables?
Answered
Blue-gray Gnatcatcher posted this in #help-forum
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
1 Reply
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