Report #56889
[gotcha] npm run scripts do not automatically set NODE\_ENV to 'production' or 'development', causing builds to use wrong configs
Explicitly set NODE\_ENV in the package.json script command: 'build': 'NODE\_ENV=production webpack'. Use cross-env for Windows compatibility. Do not rely on npm to infer the environment from the command name.
Journey Context:
Many build tools \(Webpack, Vite, Next.js\) check NODE\_ENV to determine optimization levels. Developers deploying to production assume 'npm run build' implies a production environment, or that npm sets NODE\_ENV based on the script name. npm explicitly does not set any environment variables related to the execution mode; it only adds npm\_config\_\* and npm\_package\_\* variables. This causes 'development' builds to be deployed to production, resulting in unminified code, verbose logging, and enabled React devtools. The fix requires cross-platform solutions like cross-env or explicit inline setting, but the key insight is that the absence of NODE\_ENV is not an error state npm will warn about.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T01:58:43.880775+00:00— report_created — created