I could possibly be misunderstanding this, but I ran the command volta pin [email protected].
This added "volta": {
"node": "12.13.0"
} to my package.json
But when I open up a new terminal in vscode, and run node --version its 10.X.X. When using an actual Mac terminal, Volta correctly changes node to the right version
@bakerac4 Thanks for creating this issue, we actually were just discussing this behavior in the discord channel. Can you share the OS (looks like MacOS) and shell that you are using? It's been difficult to diagnose this as we can't seem to reproduce it, so any pointers to your setup would be helpful.
Also, within the VS Code terminal that doesn't run correctly, what is the output of which node?
@bakerac4 and @knownasilya (who also reported this): After digging through the VS Code repo a little bit, I think I may have an idea what's going on: VS Code launches the terminal _starting_ with the existing environment variables, including the existing PATH (which includes Volta). However, the terminal then runs its startup scripts which continue to modify the PATH.
The entry that Volta adds to startup scripts tries to avoid creating duplicate PATH entries, so it sees that ~/.volta/bin is already on the PATH and does nothing. Unfortunately other directories get prepended ahead of Volta, which then causes the shims to not work because the terminal resolves to a Node installed by another tool instead of the Volta shim.
Can either of you try editing your profile scripts (~/.profile, ~/.bash_profile, ~/.bashrc, ~/.config/fish/config.fish, and/or ~/.zshrc) to make the script always append? For non-Fish shells, the change would be:
- grep --silent "$VOLTA_HOME/bin" <<< $PATH || export PATH="$VOLTA_HOME/bin:$PATH"
+ export PATH="$VOLTA_HOME/bin:$PATH"
While for config.fish, the change should be:
- string match -r ".volta" "$PATH" > /dev/null; or set -gx PATH "$VOLTA_HOME/bin" $PATH
+ set -gx PATH "$VOLTA_HOME/bin" $PATH
Once that is complete, try exiting and restarting VS Code and see if that solves the issue. If it does, we can make a change for the next release to _always_ append the PATH and ensure that Volta works in VS Code. Thanks!
Worked for me using fish.
Also worked for me using non-fish in ~/.bash_profile. Thanks!
Most helpful comment
@bakerac4 and @knownasilya (who also reported this): After digging through the VS Code repo a little bit, I think I may have an idea what's going on: VS Code launches the terminal _starting_ with the existing environment variables, including the existing
PATH(which includes Volta). However, the terminal then runs its startup scripts which continue to modify thePATH.The entry that Volta adds to startup scripts tries to avoid creating duplicate PATH entries, so it sees that
~/.volta/binis already on the PATH and does nothing. Unfortunately other directories get prepended ahead of Volta, which then causes the shims to not work because the terminal resolves to a Node installed by another tool instead of the Volta shim.Can either of you try editing your profile scripts (
~/.profile,~/.bash_profile,~/.bashrc,~/.config/fish/config.fish, and/or~/.zshrc) to make the script always append? For non-Fish shells, the change would be:While for
config.fish, the change should be:Once that is complete, try exiting and restarting VS Code and see if that solves the issue. If it does, we can make a change for the next release to _always_ append the PATH and ensure that Volta works in VS Code. Thanks!