Report #18027
[gotcha] npm scripts use different shells on Windows vs Unix causing cross-platform environment variable syntax failures
Use cross-env npm package for setting environment variables: cross-env NODE\_ENV=test node app.js. Alternatively, set script-shell to bash in .npmrc for Windows \(requires Git bash\), or move complex logic to a Node.js script file executed by npm instead of inline shell commands.
Journey Context:
npm prepends node\_modules/.bin to PATH for script execution, but on Windows it spawns cmd.exe while on Unix it uses /bin/sh. This causes inline environment variables \(FOO=bar cmd\) to fail on Windows \(cmd uses set FOO=bar && cmd syntax\). Developers write "ENV=test node app.js" which works on macOS/Linux but fails on Windows with 'ENV=test' is not recognized. The inconsistency is by design \(using system default shells\), making cross-platform npm scripts impossible without cross-env abstraction or Node.js script indirection.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T06:57:50.791417+00:00— report_created — created