Report #13325
[gotcha] npm\_lifecycle\_event contains script name but npm\_lifecycle\_script contains command string, causing env var confusion
Use npm\_lifecycle\_event to detect which npm script is running \(e.g., 'build', 'install'\). Use npm\_lifecycle\_script only if you need the literal shell command being executed. Never assume npm\_lifecycle\_event contains the command.
Journey Context:
npm injects environment variables into lifecycle scripts, but the naming is counter-intuitive: npm\_lifecycle\_event holds the script key \(like 'postinstall'\), while npm\_lifecycle\_script holds the literal command string from package.json \(like 'node-gyp rebuild'\). Developers often check npm\_lifecycle\_script expecting the script name, causing logic to fail when commands are refactored. Additionally, npm\_lifecycle\_event is reliable across npm versions, whereas other vars like npm\_script\_name don't exist. This distinction is critical when writing cross-platform lifecycle hooks that need to detect the execution context.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T18:22:39.097511+00:00— report_created — created