Volta: VS Code Terminal not using correct node version

Created on 13 Feb 2020  路  4Comments  路  Source: volta-cli/volta

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

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 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!

All 4 comments

@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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mikrostew picture mikrostew  路  5Comments

chriskrycho picture chriskrycho  路  5Comments

PrsPrsBK picture PrsPrsBK  路  4Comments

elwayman02 picture elwayman02  路  4Comments

rwjblue picture rwjblue  路  3Comments