ENV variables undefined in production
Answered
Selkirk Rex posted this in #help-forum
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.3 Replies
@Selkirk Rex 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.
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
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