Skip to content
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

Run node version detection in a real shell #717

Closed
connor4312 opened this issue Aug 21, 2020 · 3 comments
Closed

Run node version detection in a real shell #717

connor4312 opened this issue Aug 21, 2020 · 3 comments
Assignees
Milestone

Comments

@connor4312
Copy link
Member

Currently, depending on how VS Code is launched, version managers like nvm and nvs (which depend on setting environment variables) might not have their variables set in the context of the VS Code application. This can cause lookups to fail, or to find the wrong Node versions.

@connor4312 connor4312 added the feature-request Request for new features or functionality label Aug 21, 2020
@connor4312 connor4312 self-assigned this Aug 21, 2020
@connor4312
Copy link
Member Author

connor4312 commented Aug 25, 2020

I looked into this a bit. The fix is possible but somewhat complicated to do correctly across platforms--the most primitive form of this is running a non-interactive login shell sh -l -c "which <binary> && readlink -f <binary>". However, this is complicated to do across platforms--for example, that command fails in WSL, we need to shell-escape the binary, ...--and adds a full second of latency on my system, which is not an acceptable default.

On most systems it seems that the desktop environment reads from the ~/.profile file (but not the bash profile) so a simpler solution to people facing this problem is to:

  1. Move their version manager initialization parameters from .bashrc/.zshrc/... into .profile
  2. Log out and in again. Then desktop applications should be launched with those variables.

Alternately, you can launch code from the command line so that it inherits environment variables (make sure all previous instances of VS Code are closed, then run code in the terminal)

There are also various ways to set the variable for a specific application, for example on Ubuntu: https://help.ubuntu.com/community/EnvironmentVariables#Launching_desktop_application_with_an_environment_variable

@zztiswb116
Copy link

zztiswb116 commented Sep 29, 2020

I looked into this a bit. The fix is possible but somewhat complicated to do correctly across platforms--the most primitive form of this is running a non-interactive login shell sh -l -c "which <binary> && readlink -f <binary>". However, this is complicated to do across platforms--for example, that command fails in WSL, we need to shell-escape the binary, ...--and adds a full second of latency on my system, which is not an acceptable default.

On most systems it seems that the desktop environment reads from the ~/.profile file (but not the bash profile) so a simpler solution to people facing this problem is to:

  1. Move their version manager initialization parameters from .bashrc/.zshrc/... into .profile
  2. Log out and in again. Then desktop applications should be launched with those variables.

Alternately, you can launch code from the command line so that it inherits environment variables (make sure all previous instances of VS Code are closed, then run code in the terminal)

There are also various ways to set the variable for a specific application, for example on Ubuntu: https://help.ubuntu.com/community/EnvironmentVariables#Launching_desktop_application_with_an_environment_variable

I move this code from .zshrc to .profile but still worng

export NVM_DIR="$HOME/.nvm"
  [ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh"  # This loads nvm
  [ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

image

when I run nvm --version
image

how fix this

@connor4312
Copy link
Member Author

If you're on OSX, it looks like you have a different file: https://stackoverflow.com/questions/135688/setting-environment-variables-on-os-x?answertab=votes#tab-top

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

2 participants