Pro Tip — Developing on Windows: Setting variables in your script command

Kirk Clarke
Jul 12, 2021
Photo by Tadas Sar on Unsplash

Recently while working on an older node project on windows, I discovered my NODE_ENV variable was coming up as ‘undefined. Turns out npm uses cmd by default and that doesn’t support command substitution. Within my project, the node module “cross-env” was updating the process.env variable(s) and the offered solution was to update the .npmrc script-shell to PowerShell. Personally, I wanted to avoid this since that would mean I or anyone else who wants to work on the repo from a non-windows OS, they’d have to maintain a .npmrc file of their own.

The Fix

Add a windows specific script command that uses “set” instead of “cross-env” (also removing the space before the ‘&&’ if doing more than one command).

Just an example of a quick workaround.

--

--

Kirk Clarke

Senior Web (UI/UX) Designer & Engineer. Loves learning new things and solving problems. https://kirkclarke.com/ https://twitter.com/kclarkedesign