Problems on Windows - Help! No such file or directory 2: ./node_modules/pre-commit/hook : integer expression expected: [: 127 : numeric argument required 5:
replete opened this issue · 7 comments
I've been pulling my hair out trying to make sense of this for someone I'm working with who is having this problem. It's breaking their workflow.
No such file or directory 2: ./node_modules/pre-commit/hook
: integer expression expected: [: 127
: numeric argument required 5:
I've tried Windows machines near me, and VMs and don't have the problem.
This happens in cmd, powershell, MinGW, WebStorm
.
Any ideas?
Same problem with babun on Windows 7, I got this when I try to commit :
: No such file or directory .git/hooks/pre-commit: line 2: ./node_modules/pre-commit/hook
: integer expression expected .git/hooks/pre-commit: line 4: [: 127
: numeric argument required .git/hooks/pre-commit: line 5: exit: 0
Hope we'll find a solution
Same here on Windows 10 in WSL Bash
Same on Windows 7
If you open up .git/hooks/pre-commit
, you can see that the code is written in bash:
#!/bin/bash
./node_modules/pre-commit/hook
RESULT=$?
[ $RESULT -ne 0 ] && exit 1
exit 0
Interestingly enough, I get the same message in Cygwin, but I don't in Git bash's mingw64.
In any case, the problem is probably something something doesn't understand bash.
Cygwin:
$ uname -r
2.10.0(0.325/5/3)
$ git --version
git version 2.16.2
Git bash:
$ git --version
git version 2.5.0.windows.1
EDIT: this is a red herring. See next comment for details.
Update: looks like .git/hooks/pre-commit
was not happy about the line ending. It had \r\n
(Windows). Switching to \n
got me further.
EDIT: looks like it purposely chooses Windows line ending (
Lines 104 to 108 in f25888f
I suspect the problems I am encountering are specific to Cygwin, so if you're not using Cygwin, give the above a shot.
This is the full error after changing the line endings:
> git commit -m "test"
/cygdrive/c/Program Files/nodejs/node
pre-commit:
pre-commit: Received an error while parsing or locating the `package.json` file:
pre-commit:
pre-commit: Cannot find module '\cygdrive\c\path\to\package.json'
pre-commit:
pre-commit: Skipping the pre-commit hook.
pre-commit:
It looks like it's failing on
Line 49 in f25888f
I am using Cygwin Git with a Windows Node installation. This makes sense to me, since Windows Node probably doesn't understand a non-Windows path.
Using "C:\Program Files\Git\bin\git" commit -m "test"
works for me, and surprisingly, with pre-commit
containing either line ending. Looks like Windows Git with Windows Node installation works out-of-the-box.
Hopefully this helps!
In node_modules/pre-commit/index.js
change line
this.json = require(path.join(this.root, 'package.json'));
to
this.json = require(path.join(this.root, 'package.json').replace(/\\([a-zA-Z])\\/, '$1:\\'));
This will change \c\Users\rofrol\project1\package.json
to c:\Users\rofrol\project1\package.json
.