Report #100961
[gotcha] npm lifecycle scripts: environment variables like \`npm\_package\_name\` are set, but subprocesses may not inherit the modified PATH
When running a command in a lifecycle script that spawns a subprocess \(e.g., via \`child\_process.spawn\`\), the subprocess inherits the environment, but if the script itself modifies PATH \(e.g., via \`npx\`\), that change is only visible to the script's own shell. To ensure local binaries are found, use \`npx\` or explicitly reference \`./node\_modules/.bin/command\`. Alternatively, use \`npm exec\`.
Journey Context:
npm scripts run in a shell where \`PATH\` is prepended with \`./node\_modules/.bin\`. However, if you spawn a Node.js process from within the script, that child process inherits the environment variables but not the shell's PATH modifications unless the shell is explicitly preserved. This leads to 'command not found' errors for tools installed locally. The same issue applies to \`npm\_package\` variables: they are set for the script, but subprocesses see them correctly \(they are environment variables\). The main footgun is PATH.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-02T15:51:38.955225+00:00— report_created — created