0

I am just trying to understand the delta between the setup of my last windows laptop and my new one.

Notes:

  • OLD runs windows 10, NEW runs windows 11.
  • using git bash in both.
  • WSL enabled in features in both (not sure if this matters at all).
  • nvm controls node version in both.
  • running an npm script defined as: NODE_ENV=production gulp build.
  • no cross-env, win-node-env or similar packages installed on old one, globally or in the project.
  • nothing in the windows PATH environment variable on either that would seem to affect this.

OLD works fine, NEW gives the error: 'NODE_ENV' is not recognized as an internal or external command, operable program or batch file.

Why would this happen on one and not the other? What else can I check? Happy to use cross-env and probably will, but I really just want to understand. Happy to provide any more details.

Damo
  • 5,698
  • 3
  • 37
  • 55
noahmason
  • 113
  • 5
  • I don't think this is a WSL question, if you type help at the command prompt what do you get back, a version number like "GNU bash, version 5.2.15(1)-release (x86_64-pc-msys)" or an error? – Damo Jul 18 '23 at 08:12
  • @Damo No error, I get the help response: `GNU bash, version 5.2.15(1)-release (x86_64-pc-msys)` – noahmason Jul 18 '23 at 12:11
  • @Damo Figured out the issue, See my answer below. – noahmason Jul 18 '23 at 13:42

1 Answers1

0

Okay I figured it out - It turns out that npm was using cmd for its script shell, even though I am running the command in git bash.

The fix is quite simple, set bash as the script shell and voila. No need for cross-env (or any other normalizer for that matter), and all of your developers can use the same scripts regardless of their OS.

Set the npm script shell:

npm config set shell "C:\\Program Files\\Git\\bin\\bash.exe"
npm config set script-shell "C:\\Program Files\\Git\\bin\\bash.exe"

This will add entries to your .npmrc file as:

script-shell=C:\Program Files\Git\bin\bash.exe
shell=C:\Program Files\Git\bin\bash.exe

May be a good idea to close and reopen your terminal.

noahmason
  • 113
  • 5