Quantcast
Channel: A shell script to check the version of NodeJS doesn't work in Git Bash on Windows - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by hlovdal for A shell script to check the version of NodeJS doesn't work in Git Bash on Windows

$
0
0

The problem here is a mismatch in expectations of how a terminal should behave from a program with unix/posix expectations compared to how terminals behave on windows. This is a known problem, and there is a longer discussion of the issue on the nodejs repository (although this is not unique to just nodejs).

To compensate there is a tool winpty which provides the missing expectations (or alternatively node-pty), although you normally do not need to install explicitly, it should be included in the normal Git bash installation.

For this reason node is normally set up to be an alias for winpty node, although that causes problems for stout/stdin redirects, so a common practice is to then invoke node as node.exe (e.g. node.exe --help | wc -l) to sometimes avoid using winpty.

For your case you probably want to change your script to

if ...is-running-on-windows... # Check https://stackoverflow.com/q/38086185/23118then    # I expect one of these to work    NODE_BINARY=node.exe    NODE_BINARY="winpty node"else    NODE_BINARY=nodefinode_version=$($NODE_BINARY -v) 

Viewing all articles
Browse latest Browse all 2