Stray .env file silently broke 13 Next.js build pages while dev mode ran fine
A developer debugging a Next.js 14 SaaS app discovered that exactly 13 pages consistently failed during production builds with a 'TypeError: Invalid URL' error, while the development server showed no issues. Rolling back through weeks of git commits reproduced the same failure, ruling out any recently written code as the cause. The root cause turned out to be a leftover .env file from a debugging session a month earlier, which was invisible to version control and code review. Next.js loads environment files in a specific priority order, meaning a stray .env file could silently override or corrupt values like NEXTAUTH_URL without appearing in any diff. The incident highlights how environment-layer bugs can evade standard debugging practices, since the application code itself was never incorrect.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in