2

...I wrote some scripts for the package.json of a node project. when I use some syntax, for example, BUILD_PATH= in the script I am only able to run this npm script whit the WLS command line (Linux) but for using with bash in windows it throws an error. I'm wondering are there any tools to run such scripts like this both in windows and Linux?

example: from my package.json

"scripts":
{"build": "BUILD_PATH=../server/public react-scripts build"}

when I execute that with the Linux command line (WSL) it goes well. but with windows, it throws an error.

I know what windows equivalent for this command. but I wondering one tool or package to do this automatically.

Ebay
  • 355
  • 2
  • 12
  • Try the first answer here https://stackoverflow.com/questions/55300421/how-can-i-make-npm-projects-with-bash-shell-commands-work-on-windows – Dipanshu Kumar Suman May 13 '21 at 13:09
  • thank you for your answer; okay...I know there is WSL and with it there no error.... but my question is different – Ebay May 13 '21 at 15:06
  • Yeah, the link i posted above solves your question. And it is same as your solution but with more explanation. – Dipanshu Kumar Suman May 14 '21 at 10:58
  • right... but the main part of my problem was: the npm didn't use the git bash as default ...of course it was helpful and I am thankful for your response. :) – Ebay May 15 '21 at 10:27

1 Answers1

5

I have found the npm default shell isn't git, although I run the npm command in bash. to fix it, It needs to run the following command to replace bash as a default shell.

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

I hope it helps and works for other people that might be faced with this issue.

Ebay
  • 355
  • 2
  • 12