Right on, Blaine Garrett.
FTR I did exhaustive tests including NODE_ENV=development next start,
NODE_ENV=production next dev,
etc -- but I'm also currently stuck on v10.2.3. Maybe this has since changed in v11 or v12.
IMHO Next.js made a rare misstep in being both opinionated and rigid about proper support for true 12-factor config that lives in the runtime deploy environment. It probably stems from their original desire to stay "close" to create-react-app, and ofc whatever most closely aligns with Vercel's preferred hosting model. (shrug)
Slainte,
Chris
PS See also
github.com/vercel/next.js/issues/12772
and
github.com/vercel/next.js/discussions/25764
Hi Blaine Garrett,
Thanks for sharing a great writeup about a gnarly topic.
I have a minor correction to share. You wrote:
"Note: This hierarchy optionally goes further with
.env.developmentand.env.production(corresponding to the value of NODE_ENV)..."But they don't actually correspond to the value of NODE_ENV. Next.JS bases its decision to read from
.env.developmentvs.env.productionon one thing only: whether you start the app withnext devornext start. That's all. NODE_ENV's value is irrelevant to that bit of Next-specific logic.AFAICT you get the rest of the complicated picture right; hopefully my comment will inspire you to edit the post, or at least help ensure other readers aren't accidentally misled.
Slainte, Chris