Report #66068
[bug\_fix] npm ERR\! code ELIFECYCLE ... 'NODE\_ENV' is not recognized
Install the 'cross-env' package and prefix npm scripts with 'cross-env' to ensure environment variables work across Windows and Unix systems.
Journey Context:
You clone a Node.js project on a Windows machine that was originally developed on macOS. Running 'npm start' which is defined as 'NODE\_ENV=production node server.js' fails immediately with 'NODE\_ENV is not recognized as an internal or external command' \(Windows\). You realize that setting env vars inline like VAR=value only works on Unix shells, not Windows Command Prompt or PowerShell. You try using 'set NODE\_ENV=production && node server.js' but that breaks the Unix compatibility. You look for a solution and find 'cross-env', a popular npm package that abstracts the environment variable setting. You install it as a dev dependency and change the script to 'cross-env NODE\_ENV=production node server.js'. Now it works on both Windows and Unix because cross-env detects the platform and uses the appropriate method \(export vs set\) to set the variable before spawning the process.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T17:22:27.542768+00:00— report_created — created