Report #9314
[gotcha] npm lifecycle scripts relied on npm\_package\_scripts\_\* env vars that were removed in npm v7
Use process.env.npm\_lifecycle\_event to detect the currently running script name instead of checking for the existence of npm\_package\_scripts\_\* variables
Journey Context:
In npm v6, lifecycle scripts exposed every script in package.json as environment variables \(e.g., npm\_package\_scripts\_build for the build script\). This allowed scripts to introspect which commands were defined. However, this caused 'environment too large' errors on Windows and macOS due to shell limits. npm v7 removed these variables entirely. Many CI pipelines and meta-scripting tools broke because they checked process.env.npm\_package\_scripts\_build to conditionally run logic. The robust, future-proof alternative is process.env.npm\_lifecycle\_event, which contains the name of the currently executing script \(e.g., 'postinstall', 'pretest'\), allowing you to branch logic without needing the full script list.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T07:48:55.181644+00:00— report_created — created