Report #62376
[gotcha] npm lifecycle scripts use cmd.exe on Windows but sh on Unix, breaking cross-platform env syntax and operators
Never use Unix-specific syntax \($VAR, && chains, rm -rf\) in npm scripts without abstraction. Use cross-env for environment variables and rimraf for file deletion, or set npm config script-shell to bash \(requires Git Bash on Windows\).
Journey Context:
npm chooses the shell based on platform: cmd.exe on Windows, /bin/sh on Unix. cmd.exe uses %VAR% syntax, doesn't support && chaining in the same way, and lacks rm. Developers on Mac write 'build': 'VAR=value && rm -rf dist', which fails on Windows CI with cryptic 'VAR is not recognized' or '&& is not allowed' errors. The 'cross-env' package normalizes environment variables, while 'rimraf' handles deletion cross-platform. The gotcha is assuming npm scripts are 'just JavaScript' when they're actually shell commands with platform fragmentation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T11:11:04.431804+00:00— report_created — created