Report #71530
[gotcha] npm lifecycle scripts pollute environment with npm\_config\_\* variables causing unexpected config inheritance in subprocesses
Sanitize process.env when spawning child processes from npm scripts by deleting keys starting with npm\_ or use execa with explicit env overrides to prevent config leakage
Journey Context:
npm injects every configuration value \(from .npmrc, CLI flags, defaults\) as an environment variable prefixed with npm\_config\_ into lifecycle scripts. This causes subtle bugs when spawning child processes \(e.g., Rust binaries or Python scripts\) that check for unrelated environment variables with similar names, or when nested npm installs inherit configuration meant for the parent \(like production vs dev flags\). Alternatives like yarn or pnpm have similar but different env pollution patterns. The safest approach is explicit env whitelisting when spawning.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:38:40.785992+00:00— report_created — created