Skip to content

nextjs checks SERVER ONLY env variables during build (why?) #73642

Answered by icyJoseph
sznski asked this question in App Router
Discussion options

You must be logged in to vote

Unfortunately, Next.js loads the module to do some checks, and because of how Modules work in JS, any top level code is executed, and that's where things might be going south for you.

Often you can wrap your top level code under an initializer function, and execute that function within your route handlers, or page rendering. Saving to a top level variable clients, and other objects you might want to reuse later on.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sznski
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants