Report #54887
[gotcha] npm lifecycle scripts modify PATH order differently across npm versions causing binary resolution bugs
Always use \`npx \` or explicit \`./node\_modules/.bin/\` paths in scripts instead of relying on bare commands; pin npm version in \`engines\` field to avoid npm v6 \(appends\) vs v7\+ \(prepends\) behavior changes.
Journey Context:
Developers assume that running \`cmd\` in an npm script behaves like \`npx cmd\`, resolving to the local \`node\_modules/.bin\`. However, npm modifies \`PATH\` to include \`.bin\`, but the order changed: npm v6 appended \(system binaries shadow local\), while npm v7\+ prepends \(local shadows system\). Additionally, environment variables like \`npm\_execpath\` point to the npm binary, not the node binary, causing confusion when spawning child processes. In monorepos with nested \`node\_modules\`, the PATH resolution depends on which directory npm executes from, leading to 'command not found' or 'wrong version' errors in CI \(older npm\) versus local dev \(newer npm\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T22:37:17.397562+00:00— report_created — created