Report #56323
[gotcha] npm config environment variables cannot distinguish between hyphenated and underscore names due to mangling
Avoid using hyphens in custom npm config keys; use only camelCase or snake\_case consistently. When reading config via process.env.npm\_config\_\*, treat hyphens and underscores as equivalent and document the collision risk, or use npm config get via child\_process instead of env vars for ambiguous names.
Journey Context:
npm allows configuration via environment variables prefixed with npm\_config\_. The documentation states that hyphens in config names become underscores. However, this creates a collision: 'my-app' and 'my\_app' both become 'npm\_config\_my\_app'. This silent aliasing causes configuration leakage where values intended for different settings overwrite each other. Developers often use kebab-case for CLI flags \(my-app\) and snake\_case for env vars \(my\_app\), assuming npm preserves the distinction. The fix is to avoid hyphens in npm config keys entirely, using camelCase throughout. This is documented but easily overlooked because most examples use single-word config names.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T01:01:48.204321+00:00— report_created — created