volta-cli / volta

Volta: JS Toolchains as Code. ⚡
https://volta.sh
Other
11.15k stars 238 forks source link

Husky precommit cannot find Node on Volta #1134

Open chunghaw-tsengfang opened 2 years ago

chunghaw-tsengfang commented 2 years ago

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 node@16.13.2 as default
   note: you are using node@14.18.3 in the current project
success: pinned node@14.18.3 in package.json
success: pinned yarn@1.22.17 in package.json
success: pinned yarn@1.22.17 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
charlespierce commented 2 years ago

@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).

patapata5050 commented 2 years ago

@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"
thinksentient commented 2 years ago

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

# ~/.huskyrc
export PATH=$PATH:~/.volta/bin
patapata5050 commented 2 years ago

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

Phault commented 1 year ago

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.

brandonsturgeon commented 4 months ago

I had this issue even with a .huskyrc. The husky error output would print its PATH and I could clearly see my /Users/me/.volta/bin in there, and it still couldn't find it.

In my case I was using a terminal so I just closed that window and opened a new one - worked fine 🤷