Open tauren opened 7 years ago
I have the same issue with zsh
, though slightly different setup, I use tower
. Recently I blew away all my node/npm/n installations, and reinstalled n
.
./node_modules/pre-commit/hook: line 49: : command not found
./node_modules/pre-commit/hook: line 49: : command not found
./node_modules/pre-commit/hook: line 51: shell_session_update: command not found
This works fine, so I don't see why the hook
is failing:
~ ❯❯❯ which node
/Users/kross/n/bin/node
~ ❯❯❯ node -v
v8.1.0
I can also execute the hook.
From in the project:
./node_modules/pre-commit/hook
No errors!
From outside the project (I expect problems, but it finds node):
❯❯❯ ./projects/ui/node_modules/pre-commit/hook
module.js:487
throw err;
^
Error: Cannot find module 'pre-commit'
at Function.Module._resolveFilename (module.js:485:15)
at Function.resolve (internal/module.js:18:19)
at [eval]:1:21
at ContextifyScript.Script.runInThisContext (vm.js:44:33)
at Object.runInThisContext (vm.js:116:38)
at Object.<anonymous> ([eval]-wrapper:6:22)
at Module._compile (module.js:569:30)
at evalScript (bootstrap_node.js:432:27)
at startup (bootstrap_node.js:139:9)
at bootstrap_node.js:575:3
So, I don't have any idea why within tower
it is having a problem. I can which node
anywhere...
I added set -x
and see that it cannot find node:
++ which node
++ which nodejs
++ which iojs
+ HAS_NODE=
+ [[ -z '' ]]
+ source_home_file .bash_profile
+ file=/Users/kross/.bash_profile
+ [[ -f /Users/kross/.bash_profile ]]
+ source /Users/kross/.bash_profile
++ [[ -s /Users/kross/.profile ]]
++ source /Users/kross/.profile
...
++ which node
+ NODE=
++ which nodejs
+ NODEJS=
++ which iojs
+ IOJS=
+ LOCAL=/usr/local/bin/node
+ BINARY=
+ [[ -n '' ]]
+ [[ -n '' ]]
+ [[ -n '' ]]
+ [[ -x /usr/local/bin/node ]]
+ [[ '' == *--dry-run* ]]
++ '' -e 'console.log(require.resolve('\''pre-commit'\''))'
./node_modules/pre-commit/hook: line 54: : command not found
+ '' ''
./node_modules/pre-commit/hook: line 54: : command not found
+ shell_session_update
./node_modules/pre-commit/hook: line 56: shell_session_update: command not found
@tauren I found my problem by adding set -x
to the script. I had an old ~/.bash_profile
lingering.
e.g.
+ source_home_file .bash_profile
+ file=/Users/kross/.bash_profile
+ [[ -f /Users/kross/.bash_profile ]]
+ source /Users/kross/.bash_profile
++ [[ -s /Users/kross/.profile ]]
++ source /Users/kross/.profile
The moment I rm ~/.bash_profile
, tower
executed properly.
I had the issue for days, and found out that I did not have the path for node bin set in my .zshrc.
I just needed to add : export PATH="/usr/local/bin:$PATH"
Had same issue with sourcetree where pre-commit hook would fail and prevent me from committing in the client. Added /usr/local/bin
to path as mentionned by @yohannprigent and it fixed it. thanks!
I just encountered the same, the reason is default shell not zsh, use chsh -s to change default shell to zsh
▶ whereis brew
brew: /opt/homebrew/bin/brew /opt/homebrew/share/man/man1/brew.1
I just needed to add : export PATH="/opt/homebrew/bin:$PATH" in my '.zshrc'.
I am using the
zsh
shell with oh-my-zsh. I also often use the SourceTree client. Lastly, I'm using react-boilerplate which usespre-commit
.When I commit from the command line (zsh shell), everything works ok. But I just started getting errors when committing from inside the SourceTree client (which worked fine yesterday):
I've been using this setup for quite some time without issues, and I'm not quite sure what changed. The most recent thing I did was blow away
node_modules
in myreact-boilerplate
project and runnpm install
again. I did update to the latest SourceTree a few days ago, but I'm pretty sure I've committed using it since then. I tried updating topre-commit@1.2.2
from1.1.3
, but the same thing happens.As with any oh-my-zsh setup, my
~/.zshrc
file sources~/.oh-my-zsh/oh-my-zsh.sh
. This file executesautoload
which is a ZSH shell command and blows up. It looks likepre-commit
is running in a bash shell, so the command wouldn't be available.But what I don't understand how it was ever working... This error just started, and my OMZ script has had
autoload
in it forever.Is there something I can do to fix this? Can
pre-commit
take measures to run with the correct shell? Anything else I should do?