Report #36399
[bug\_fix] npm ERR\! code ELIFECYCLE npm ERR\! errno 1 \(with 'NODE\_ENV' is not recognized or 'rm' is not recognized\)
Install the cross-env npm package and prefix environment variable assignments and cross-platform commands in package.json scripts with cross-env \(e.g., "build": "cross-env NODE\_ENV=production webpack"\).
Journey Context:
A full-stack developer writes an npm script "build": "NODE\_ENV=production webpack && rm -rf dist" on their macOS machine. It works perfectly. They push to a shared repository where the CI pipeline runs on Windows runners. The build immediately fails with npm ERR\! code ELIFECYCLE. Examining the logs above the ELIFECYCLE error reveals 'NODE\_ENV' is not recognized as an internal or external command. The developer realizes that npm scripts execute in the default system shell: cmd.exe on Windows \(which uses set KEY=value syntax\), bash on Linux/macOS \(which uses KEY=value syntax\). The && operator behavior also differs slightly. They try using win-node-env package which helps but doesn't solve the rm command issue. Installing cross-env solves both problems because it is a Node.js executable that parses the command line, sets environment variables in process.env using Node.js's cross-platform APIs, and then spawns the remaining command in a way that works identically on all platforms. This normalizes the environment variable syntax and command execution before the shell-specific interpretation occurs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T15:34:23.659240+00:00— report_created — created