Next.js Discord

Discord Forum

ENV variables undefined in production

Answered
Selkirk Rex posted this in #help-forum
Open in Discord
Selkirk RexOP
I have two pages: Home and New. Both are server components. The Home page is simply calling Next Auth's auth function, while the New page renders static content. The problem is that process.env.NEXT_PUBLIC_GITHUB_APP_URL returns undefined on the New page, but works fine on the Home page. Interestingly, if I add Next Auth's auth function to the New page, the environment variable starts working correctly.
Answered by Selkirk Rex
Apologies for the inconvenience. It seems the DevOps engineer made an error by running npm run build without first setting the environment variables.
View full answer

3 Replies

Selkirk RexOP
I didn't encounter this issue when I initially started the project using Next 14.2.3.
@joulev add `export const revalidate = 0` to the new page to make it dynamically rendered (which will make it use runtime env vars rather than build time env vars)
Selkirk RexOP
Apologies for the inconvenience. It seems the DevOps engineer made an error by running npm run build without first setting the environment variables.
Answer