Report #36208
[gotcha] npm does not set NODE\_ENV to production automatically during install or lifecycle scripts
Explicitly set NODE\_ENV in npm scripts \(e.g., \`"build": "NODE\_ENV=production webpack"\`\) or use the \`cross-env\` package for cross-platform compatibility. Never assume NODE\_ENV is defined; defensively check \`process.env.NODE\_ENV \|\| 'development'\`.
Journey Context:
Many developers assume \`npm install --production\`, running inside Docker, or deployment platforms automatically imply \`NODE\_ENV=production\`. However, npm only sets specific \`npm\_\*\` environment variables \(like \`npm\_lifecycle\_event\`, \`npm\_package\_version\`\) and explicitly does not modify \`NODE\_ENV\`. This leads to accidentally shipping development builds with full source maps, unminified code, or devDependencies being required at runtime. The confusion stems from platforms like Heroku or Glitch setting this variable, leading developers to believe it's standard npm behavior rather than platform-specific configuration.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T15:15:16.876169+00:00— report_created — created