Skip to content

volta setup does not setup env variable PATH correctly if node is installed with brew #2018

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

Open
andidev opened this issue Mar 13, 2025 · 0 comments

Comments

@andidev
Copy link

andidev commented Mar 13, 2025

@gautamprikshit1 @chriskrycho PR #1537 is causing a bug with brew

When running vite setup I expect volta bin path /Users/username/.volta/bin to be added before brew bin path /opt/homebrew/bin.
But instead volta path added after which makes brew node binary override voltas.
So when running node ... command volta is not used.

Reproduce like this

❯ which node
/opt/homebrew/bin/node
❯ echo $PATH # added new lines in output of this command to make it more readable in PR
/Users/username/.sdkman/candidates/java/current/bin:
/Users/username/.bun/bin:
/opt/homebrew/bin:
/opt/homebrew/sbin:
/Users/username/.bin:
/usr/local/bin:
/System/Cryptexes/App/usr/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:
/Library/Apple/usr/bin:
/Applications/VMware Fusion.app/Contents/Public:
/Applications/iTerm.app/Contents/Resources/utilities:
/Applications/Visual Studio Code.app/Contents/Resources/app/bin:
/Applications/Visual Studio Code.app/Contents/Resources/app/bin
❯ volta setup
success: Setup complete. Open a new terminal to start using Volta!

volta setup above adds the volta path to .zshenv since PR #1537

if you then open a new terminal as mentioned and check what node version is used you will see volta bin path is added after brew bin path

❯ which node
/opt/homebrew/bin/node
❯ echo $PATH # added new lines in output of this command to make it more readable in PR
/Users/username/.sdkman/candidates/java/current/bin:
/Users/username/.bun/bin:
/opt/homebrew/bin:
/opt/homebrew/sbin:
/Users/username/.bin:
/usr/local/bin:
/System/Cryptexes/App/usr/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:
/Library/Apple/usr/bin:
/Applications/VMware Fusion.app/Contents/Public:
/Users/username/.volta/bin: <--- volta path added incorrectly after brew path
/Applications/iTerm.app/Contents/Resources/utilities:
/Applications/Visual Studio Code.app/Contents/Resources/app/bin:
/Applications/Visual Studio Code.app/Contents/Resources/app/bin

Fix with

Add the setup lines to

echo 'export VOLTA_HOME="$HOME/.volta"' >> ~/.zshrc && echo 'export PATH="$VOLTA_HOME/bin:$PATH"' >> ~/.zshrc

open new terminal and see that correct node is used and volta path is added correctly before brew bin path

❯ which node
/Users/username/.volta/bin/node
❯ echo $PATH # added new lines in output of this command to make it more readable in PR
/Users/username/.volta/bin:  <--- volta path added correctly before brew path
/Users/username/.sdkman/candidates/java/current/bin:
/Users/username/.bun/bin:
/opt/homebrew/bin:
/opt/homebrew/sbin:
/Users/username/.bin:
/usr/local/bin:
/System/Cryptexes/App/usr/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:
/Library/Apple/usr/bin:
/Applications/VMware Fusion.app/Contents/Public:
/Users/username/.volta/bin:
/Applications/iTerm.app/Contents/Resources/utilities:
/Applications/Visual Studio Code.app/Contents/Resources/app/bin:
/Applications/Visual Studio Code.app/Contents/Resources/app/bin

Worth noting is that I have not installed node with brew directly. Its installed as a transative dependency in some brew formulas, e.g. mongodb-community. So I cannot uninstall node to get volta setup to work.

❯ brew deps mongodb-community
brotli
c-ares
ca-certificates
icu4c@76
libnghttp2
libuv
mongodb/brew/mongodb-database-tools
mongosh
node
openssl@3

Possible solution

in

if shell.contains("zsh") || zshenv.exists() {

change

if shell.contains("zsh") || zshenv.exists() {
    profiles.push(zshenv);
} else if zshrc.exists() {
    profiles.push(zshrc);
}

to

if zshenv.exists() {
    profiles.push(zshenv);
} else if zshrc.exists() {
    profiles.push(zshrc);
}

Since think on macs the .zshenv does not exist by default (not 100% sure).

alternative is to revert and use only zshrc.exists() check

if zshrc.exists() {
    profiles.push(zshrc);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant