Report #11645
[gotcha] npm run script cannot access environment variables named npm\_package\_\*
npm injects npm\_package\_\*, npm\_lifecycle\_\*, and npm\_config\_\* variables into the environment, potentially shadowing user-defined variables. Rename your variables to avoid the npm\_ prefix, or explicitly pass them unprefixed in the command.
Journey Context:
npm scripts execute with a heavily modified environment. The npm CLI explicitly sets dozens of npm\_\* variables: npm\_package\_name, npm\_package\_version, npm\_lifecycle\_event, npm\_config\_user\_agent, etc. If a user exports npm\_package\_config\_foo expecting to read it in a script, npm will overwrite it with the value from package.json config or undefined. Similarly, PATH is prepended with node\_modules/.bin, which can shadow global installations. This silent shadowing causes 'variable not set' bugs that are hard to debug because 'env' in the shell shows the npm-injected values. The only reliable workaround is namespace isolation: prefix your custom env vars with your project identifier, never use npm\_ prefixes, or use cross-env to set vars inline in the script command which overrides npm's env for that specific invocation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T13:50:01.596278+00:00— report_created — created