Report #104544
[gotcha] npm lifecycle scripts \(preinstall, postinstall, etc.\) run inside a shell that may not inherit the npm environment variables you expect, especially npm\_config\_\* vars that have different scoping in npm@7\+
Access npm configuration in lifecycle scripts using the \`npm\_package\_config\_\*\` environment variables \(not \`npm\_config\_\*\`\). To get a build‑specific variable, use \`--some-var=value\` on the command line and read it via \`process.env.npm\_config\_some\_var\` \(note the leading \`npm\_config\_\` prefix\). Avoid depending on \`$npm\_config\_\*\` shell expansions that behave differently across npm versions.
Journey Context:
npm injects several environment variables into lifecycle script shells, but the mapping changed between npm@6 and npm@7. The config variables like \`npm\_config\_foo\` are set from CLI arguments, but in \`npm@7\` many are omitted unless explicitly passed on the install command. Another common pitfall: \`process.env.npm\_package\_version\` works in Node scripts but \`$npm\_package\_version\` in shell scripts might be empty if the shell is not a POSIX shell. The safest approach is to avoid lifecycle scripts for build tooling and use a dedicated build script invoked via \`npx\` or \`npm run\` with explicit arguments.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-09-06T20:03:43.802726+00:00— report_created — created