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

npm packages which come with CLI through git-bash return errors #874

Closed
1 task done
chawyehsu opened this issue Sep 5, 2016 · 7 comments
Closed
1 task done

npm packages which come with CLI through git-bash return errors #874

chawyehsu opened this issue Sep 5, 2016 · 7 comments

Comments

@chawyehsu
Copy link

chawyehsu commented Sep 5, 2016

  • I was not able to find an open
    or closed issue
    matching what I'm seeing.

Setup

  • Which version of Git for Windows are you using? Is it 32-bit or 64-bit?
$ git --version --build-options
git version 2.10.0.windows.1
sizeof-long: 4
machine: x86_64

I used version 2.9.4, then upgrade to 2.10.0, still have the problem. (reinstall doesn't resolve)

  • Which version of Windows are you running? Vista, 7, 8, 10? Is it 32-bit or 64-bit?
Microsoft Windows 10 Build 14393.rs1_release_inmarket. 160819-1924
x86_64
  • What options did you set as part of the installation? Or did you choose the
    defaults?
# One of the following:
> type "C:\Program Files\Git\etc\install-options.txt"
> type "C:\Program Files (x86)\Git\etc\install-options.txt"
> type "%USERPROFILE%\AppData\Local\Programs\Git\etc\install-options.txt"
$ cat /etc/install_options.txt
Path Option: Cmd
SSH Option: OpenSSH
CRLF Option: LFOnly
Bash Terminal Option: MinTTY
Performance Tweaks FSCache: Enabled

Details

  • Which terminal/shell are you running Git from? e.g Bash/CMD/PowerShell/other
Mintty / Bash
1. install git-for-windows
2. install node.js (I use LTS version v4.5.0)
3. install gulp through npm
   $ npm install -g gulp
4. run gulp in git-bash
   $ gulp -v
  • What did you expect to occur after running these commands?
$ gulp -v
[22:05:33] CLI version 3.9.1
  • What actually happened instead?
$ gulp -v
module.js:327
    throw err;
    ^

Error: Cannot find module 'C:\Program Files\Git\node_modules\gulp\bin\gulp.js'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:974:3

ref:

  1. pipe is returning empty string in bash in git for windows (Revisions)
  2. Can't get Gulp to work on Git Bash
  3. basedir incorrectly resolved on msysgit
  4. hexo init can't find module
  5. Other related Google search result
@dscho
Copy link
Member

dscho commented Sep 5, 2016

Does it work in cmd? In Git CMD?

@dscho dscho added the unclear label Sep 5, 2016
@chawyehsu
Copy link
Author

chawyehsu commented Sep 5, 2016

@dscho It works on cmd and powershell, but in Mintty it doesn't work.

Git CMD

image

Git Bash (Mintty)

image

Because in cmd or Git CMD the gulp command links to gulp.cmd (.bat file), while in Git Bash (Mintty) it links to gulp (shell script). And below is the gulp shell script:

#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
  "$basedir/node"  "$basedir/node_modules/gulp/bin/gulp.js" "$@"
  ret=$?
else 
  node  "$basedir/node_modules/gulp/bin/gulp.js" "$@"
  ret=$?
fi
exit $ret

In git bash the basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") is incorrectly resolved, which cause this error. For details, please take a look at the first reference I mentioned above.

@tiexo
Copy link

tiexo commented Oct 10, 2016

Cannot find module 'C:\Program Files\Git\node_modules\hexo-cli\bin\hexo

I encountered this problem more than six months, has repeatedly tried to resolve the last to nothing. Now after seeing your feedback gave me new ideas, before I do not know in cmd which is normal.

Do not know if there is a solution? Git bash still can not be used

qq 20161010164222

@chawyehsu
Copy link
Author

chawyehsu commented Oct 10, 2016

@tiexo Thanks for your feedback. I know there is a workaround, which enforce to let the basedir variable in the shell script to . (it's not a solution, because you have to modify every shell script that related to this issue. )

e.g. gulp:
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
basedir=.   <----------------------------------------------------

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
  "$basedir/node"  "$basedir/node_modules/gulp/bin/gulp.js" "$@"
  ret=$?
else 
  node  "$basedir/node_modules/gulp/bin/gulp.js" "$@"
  ret=$?
fi
exit $ret

I guess it maybe the msys runtime's problem. no idea..

@tiexo
Copy link

tiexo commented Oct 10, 2016

@h404bi thanks
After reading your solution, I think I am more suitable to use cmd ...
image

@dscho
Copy link
Member

dscho commented Aug 27, 2017

Please note that Git Bash primarily supports Git operations. So I throw the ball right back into node.js users' court.

But not without a couple of hints:

  • As it works in cmd, I imagine calling which gulp in Bash will point to a Unix shell script, while calling where gulp in cmd probably points to a .cmd script.
  • If it is a Unix shell script, calling it with bash -x /path/to/gulp ... might clarify where things go wrong.
  • The absolute path to node_modules is the pseudo root / of Git Bash. Therefore, I assume something goes wrong from determining the current working directory to turning it into an absolute path in the gulp script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants