Confusing Error When NODE_ENV Is Set Manually #78904
Replies: 1 comment
-
That's good feedback! I think this is also like that, in part because You can see how, that env var is used by libraries, to load different code, for dev, than for prod. Dev time code, might have some additional checks, debugging tools, etc, that prod mode doesn't, whereas prod code might be optimized, etc... When you run build, Next.js sets the env var for you, so that libraries and other stuff used by them and you, loads the production code branches. Dev Mode Builds!That being said! It is now possible to make development builds, https://nextjs.org/blog/next-15#:~:text=%5BImprovement%5D%20The%20experimental.allowDevelopmentBuild%20option%20can%20be%20used%20to%20allow%20NODE_ENV%3Ddevelopment%20with%20next%20build%20for%20debugging%20purposes:
From the PR, #65463:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I ran into a confusing issue and wanted to share it in case it helps others (or if it's worth improving the error message in Next.js).
If you set a non-standard value for NODE_ENV in your environment, such as:
…and then try to run:
The build fails with a cryptic error like:
This behavior was tested on:
Ubuntu 19 and 24
VirtualBox and WSL2
After some digging, I realized the issue was caused simply by having NODE_ENV set manually before build, which seems to confuse the framework during the optimization phase.
Clearing or unsetting NODE_ENV before running next build resolves the issue:
If NODE_ENV has an unexpected value during next build, it would be helpful if Next.js could detect that and emit a clearer warning or error message.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions