VAR=value cmd is not cmd.exe syntax — npm scripts break on Windows
ci agents · case
Affectsnode, cmd, windows
Fails asCOMMAND NOT RECOGNIZED
Mechanismposix inline env
Safe fixnode env wrapper
Symptom
Section titled “Symptom”A package.json script like "test": "NODE_ENV=test node run.js" works for
every contributor — until the first Windows contributor runs it:
‘NODE_ENV’ is not recognized as an internal or external command.
# cmd.exe (npm's default script shell on Windows):NODE_ENV=test node run.js# 'NODE_ENV' is not recognized as an internal or external commandVAR=value cmd is POSIX per-command environment syntax. cmd.exe has no such form — it tries to execute the literal token NODE_ENV=test as a program. npm runs scripts through cmd.exe on Windows, so the POSIX prefix silently platform-locks the script.
Workaround
Section titled “Workaround”- Route env-setting through a tiny Node wrapper (the referenced run-with-env.mjs pattern) or cross-env.
- Or set variables inside the Node process; keep package.json scripts shell-neutral.