volta icon indicating copy to clipboard operation
volta copied to clipboard

Husky precommit cannot find Node on Volta

Open chunghaw-tsengfang opened this issue 4 years ago • 6 comments

Issue

Problem

Running volta 1.0.5 and husky. On husky pre-commit, volta seems not to be able to find node. We have set the paths and even pinned the versions on the huskyrc file on top of the normal project. This problem only happens on 1.0.5 and not on 1.0.4.

Volta version: 1.0.5 Husky version: 7 Hardware: Mac OS Big Sur

Error

/Users/nishimurayuya/.volta/bin/node
/Users/nishimurayuya/.volta/bin/yarn
test==================
/Users/nishimurayuya/.volta/bin:/opt/homebrew/Cellar/git/2.34.1/libexec/git-core:/Users/nishimurayuya/.volta/tools/image/node/16.13.1/bin:/opt/homebrew/Cellar/git/2.34.1/libexec/git-core:/usr/local/git/bin:/Users/nishimurayuya/.volta/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
test==================
success: installed and set [email protected] as default
   note: you are using [email protected] in the current project
success: pinned [email protected] in package.json
success: pinned [email protected] in package.json
success: pinned [email protected] in package.json
Volta error: Node is not available.

To run any Node command, first set a default version using `volta install node`
Error details written to /Users/nishimurayuya/.volta/log/volta-error-2022-01-11_14_55_33.658.log
husky - pre-commit hook exited with code 126 (error)
git exited with error code 1

chunghaw-tsengfang avatar Jan 17 '22 07:01 chunghaw-tsengfang

@chunghaw-wevnal Sorry you're running into issues! Can you clarify a bit the setup for this project and what command you were running? As far as I can tell, there weren't any changes to resolution behavior between Volta 1.0.4 and 1.0.5, so I'm not sure how this specifically would break between the two.

We've also tested with Husky and seen it work, so I suspect this might be a little trickier to debug.

Finally, can you share the contents of the log file described in the error message? It may not be super instructive, but it should help us better understand what Volta is seeing (or not seeing).

charlespierce avatar Jan 19 '22 19:01 charlespierce

@charlespierce Hello, I have a same problem. Volta version: 1.0.5 Husky version: 7 Hardware: macOS Monterey Git client tool: Fork

When I try to do a commit using the Git client software called Fork, I get the following error message.

$ git commit --file=/var/folders/kx/_fmnlj9j3kv7bsjqf08jskf80000gn/T/BC00096D-526E-4A67-B678-F3081180CC70

.husky/pre-commit: line 4: yarn: command not found
husky - pre-commit hook exited with code 127 (error)

This seems to be due to the different PATH, as stated on Husky's official website.

https://typicode.github.io/husky/#/?id=command-not-found

If you're running Git from an app and the command can be found in your terminal, this means that the PATH in your app is different from your terminal.

To solve this, I need to put the PATH of yarn in .huskyrc, but I don't know how to write it validly in volta. The official site described how to write for nvm, so it would be great to know the volta version of this.

This is a nvm version

# ~/.huskyrc
# This loads nvm.sh and sets the correct PATH before running hook
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

patapata5050 avatar Apr 17 '22 06:04 patapata5050

Had a similar problem when using vscode git UI. This worked for me:

# ~/.huskyrc
export PATH=$PATH:~/.volta/bin

thinksentient avatar Apr 25 '22 17:04 thinksentient

@thinksentient Thank you for reply, it worked for me!!

patapata5050 avatar Apr 27 '22 13:04 patapata5050

Git GUI clients usually run the git commands in an non-interactive shell, which in the case of zsh means that ~/.zshrc isn't sourced. So volta setup should be changed to targeting either .zshenv or .zprofile instead.

Phault avatar Dec 23 '22 10:12 Phault