Report #10340
[gotcha] Environment variables exported in npm pre-scripts are not inherited by main or post-scripts due to separate subshell processes
Chain commands in a single script with && or write state to the filesystem; do not rely on env var inheritance across lifecycle phases.
Journey Context:
Developers familiar with shell scripts expect export FOO=bar in prebuild to make $FOO available in build or postbuild. However, npm spawns a new shell for each lifecycle script. Shell exports in prebuild are lost when the subshell exits. This causes variable not set errors in CI when logic is split across pre/post hooks. Workarounds include collapsing into one script: build: npm run set-env && npm run build-app, or using npm's env command, or writing to a dotenv file.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T10:21:25.820316+00:00— report_created — created