Report #17624
[gotcha] npm lifecycle scripts expose npm\_lifecycle\_event but PATH modifications cause 'command not found' for global binaries
Use npx or explicit ./node\_modules/.bin/ paths in npm scripts; use process.env.npm\_lifecycle\_event \(not npm\_lifecycle\_script\) to detect the current hook phase
Journey Context:
npm modifies the environment for lifecycle scripts: it prepends node\_modules/.bin to PATH and sets npm\_lifecycle\_event to the hook name \(e.g., 'postinstall'\). However, the PATH modification behaves inconsistently across Windows/Unix and can mask global binaries. Additionally, npm\_lifecycle\_script contains the literal script code \(useless for detection\), while npm\_lifecycle\_event contains the canonical hook name. Developers often assume the shell environment is pristine or try to parse the script content instead of using the event variable, leading to conditional logic that breaks when scripts are composed or run via npm-run-all.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T05:52:50.903937+00:00— report_created — created