Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot run Node, Error 0x2 #527

Closed
PaulBGD opened this issue Nov 11, 2015 · 26 comments
Closed

Cannot run Node, Error 0x2 #527

PaulBGD opened this issue Nov 11, 2015 · 26 comments
Labels

Comments

@PaulBGD
Copy link

PaulBGD commented Nov 11, 2015

Paul@Paul-PC:~/Documents/Coding/Fourums> node
Error 0x2 starting node.exe

Then if I try to run it in bash:

Paul@Paul-PC:~/Documents/Coding/Fourums> bash -e "node"
/c/Program Files (x86)/nodejs/node: /c/Program Files (x86)/nodejs/node: cannot execute binary file

My Node binary is x86 and I'm running bash on a 64 bit system.

@shiftkey
Copy link

What version of Git for Windows do you have installed?

@PaulBGD
Copy link
Author

PaulBGD commented Nov 11, 2015

Here's the output of git --version, not sure if this is the version of git for windows sorry:

$ git --version
git version 2.6.3.windows.1

I just downloaded it about 20 minutes ago.

@shiftkey
Copy link

And how did you source node? From nodejs.org?

@PaulBGD
Copy link
Author

PaulBGD commented Nov 12, 2015

Yes, I tried installing both x86 and x64.

@dscho
Copy link
Member

dscho commented Nov 12, 2015

@PaulBGD could you run unalias node and then try again?

@dscho dscho added the unclear label Nov 12, 2015
@PaulBGD
Copy link
Author

PaulBGD commented Nov 12, 2015

That worked, thanks! Any reason why this could have happened?

@maxime-pasquier
Copy link

Any reason why this could have happened?

Hi @PaulBGD, I think the reason is the commit build-extra/44ed99b4 who add:

alias node="winpty node.exe"

But there is no node.exe on your binaries.

Could you run unalias node && alias node="winpty node" and then try again? To see if winpty is needed or not?

@dscho
Copy link
Member

dscho commented Nov 13, 2015

@Kmelia I think the proper solution would be to test whether type -p node succeeds and points to a .exe file. If that is the case, we should set the alias. Otherwise not.

@maxime-pasquier
Copy link

@dscho your solution seems good!

@PaulBGD
Copy link
Author

PaulBGD commented Nov 13, 2015

Paul@Paul-PC / $ unalias node && alias node="winpty node"
bash: unalias: node: not found

@Kmelia

Paul@Paul-PC / $ type -p node
/c/Program Files (x86)/nodejs/node

@dscho

@PaulBGD
Copy link
Author

PaulBGD commented Nov 13, 2015

Node seems to be working fine now.

@dscho
Copy link
Member

dscho commented Nov 15, 2015

/c/Program Files (x86)/nodejs/node

@PaulBGD

The question is: what are the two first bytes of that file? IOW what does

dd if=/c/Program Files (x86)/nodejs/node bs=2 count=1 | od -t x1

print?

@PaulBGD
Copy link
Author

PaulBGD commented Nov 15, 2015

@dscho

Paul@Paul-PC / $ dd if="/c/Program Files (x86)/nodejs/node" bs=2 count=1 | od -t x1
1+0 records in
1+0 records out
2 bytes (2 B) copied, 0.000426667 s, 4.7 kB/s
0000000 4d 5a
0000002

@dscho
Copy link
Member

dscho commented Nov 16, 2015

Paul@Paul-PC / $ dd if="/c/Program Files (x86)/nodejs/node" bs=2 count=1 | od -t x1
1+0 records in
1+0 records out
2 bytes (2 B) copied, 0.000426667 s, 4.7 kB/s
0000000 4d 5a
0000002

Hmm. So it is not a Bash script as I had thought...

Oh, I guess I misunderstood the culprit completely (my only defense is that I am a bit sleep deprived these days): the issue seems to be that 64-bit winpty cannot call 32-bit executables?

/me tests that

clicketyclick

Nope, 64-bit winpty runs 32-bit git,exe just fine. Color me stumped.

@Sawtaytoes
Copy link

unalias node fixed it for me as well. I reinstalled Git 64-bit from the git-scm website and had to unalias again to run Node.

@maxime-pasquier
Copy link

and had to unalias again to run Node.

Hi @Saturn2888 you could add these lines to your .bashrc to automatically remove the unwanted aliases:

##### Git Bash for Windows >= 2.x

# remove the winpty Node aliases
unalias $(alias | grep winpty | grep node | cut -d"=" -f1 | cut -d" " -f2)

ref: http://blog.kmelia.net/testing/coloration-dans-git-bash/123

@dscho
Copy link
Member

dscho commented Dec 15, 2015

I invite everybody to investigate why winpty seems to be unable to run the 32-bit node, and also to work on the /etc/profile.d/alias.sh script to detect when to alias (and simply not alias otherwise).

@Sawtaytoes
Copy link

@Kmelia I'd love to, but somehow after installing Heroku w/ Git Bash and reinstalling Git from SCM, I lost the Git Bash prompt.

Using SourceTree's embedded Git Bash, I got this error after creating a .bashrc and putting that line in it:

WARNING: Found ~/.bashrc but no ~/.bash_profile, ~/.bash_login or ~/.profile.

So it looks like it took the .bashrc file because the node command is working now without having to unalias node each time.

@maxime-pasquier
Copy link

WARNING: Found ~/.bashrc but no ~/.bash_profile, ~/.bash_login or ~/.profile.

Check what do you have now on your home directory. Git Bash creates for you a profile file to use the .bashrc file.

The node command is working now without having to unalias node each time.

You can also check if you have the node alias with the command alias.

@Sawtaytoes
Copy link

Yeah, it created those other files and that warning went away the second time I loaded up Git Bash.

alias ipython='winpty ipython.exe'
alias ll='ls -l'
alias ls='ls -F --color=auto --show-control-chars'
alias php='winpty php.exe'
alias php5='winpty php5.exe'
alias psql='winpty psql.exe'
alias python2.7='winpty python2.7.exe'

@maxime-pasquier
Copy link

So:

The node command is working now without having to unalias node each time.

This is not correct ;) The unalias is done on the .bashrc.
So your node command is now working without the winpty

@dscho
Copy link
Member

dscho commented Jan 3, 2016

If you need to run node non-interactively, you can always call it directly with the .exe suffix.

Back to this ticket: between all the comments, my suggestion is running the danger of getting lost. So here it is again, in all its glory:

I invite everybody to investigate why winpty seems to be unable to run the 32-bit node, and also to work on the /etc/profile.d/alias.sh script to detect when to alias (and simply not alias otherwise).

@kachenjr
Copy link

This cost me some time today, and searching let me here. The error symptom is a little confusing, but the issue is that the bash command can't find the exe that is being aliased. Given the hint about the alias file and with a little searching of the intertubes, I found a post on stackoverflow that says to use command -v to verify that bash (or whatever shell) can find the executable via the PATH variable.
I set up a test

$ cat ./testCommands.sh
#!/bin/bash
if ! command -v php.exe 2>&1 > /dev/null
then
echo "php.exe not found"
else
echo "php.exe found"
fi

$ ./testCommands.sh
php.exe not found
$ export PATH=$PATH:$PATH_TO_PHP
$ ./testCommands.sh
php.exe found

So changing the alias.sh file as suggested should at least stop the odd error and fail with the more obvious not found..

alias.sh
...
for name in node ipython php php5 psql python2.7
do
if command -v ${name}.exe 2>&1 > /dev/null
then
alias $name="winpty $name.exe"
else
"Warning, ${name}.exe not found in path!"
fi
done
...
new login
bash: Warning, node.exe not found in path!: command not found
bash: Warning, ipython.exe not found in path!: command not found
bash: Warning, php.exe not found in path!: command not found
bash: Warning, php5.exe not found in path!: command not found
bash: Warning, psql.exe not found in path!: command not found
bash: Warning, python2.7.exe not found in path!: command not found

That and getting all these things in my path and I'm ready to rock and roll.
Thanks!

@kachenjr
Copy link

Actually.. to make this work, users are going to have to drop a shell script in /etc/profile.d/ that sets the path to all these things, if they aren't in the PATH setup by /etc/profile . To that end, I would recommend renaming the aliases.sh file to xaliases.sh (these are executed in alpha order), and tell users where to create the system path scripts.
Or, generate the .bash_profile for them, with this alias helper there. That way the user has the chance to set PATH in .bashrc before .bash_profile gets sourced. My $0.02.

@dscho
Copy link
Member

dscho commented Jan 21, 2016

The proper way is to use type to figure out whether the respective .exe is on the PATH.

@dscho
Copy link
Member

dscho commented Jan 21, 2016

You can find a good example here.

dscho added a commit to git-for-windows/build-extra that referenced this issue Feb 15, 2016
The user is [now presented with a nice error
message](git-for-windows/git#527) when
calling `node` while `node.exe` is not in the `PATH`

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants