-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
VS Code with NVM #1895
Comments
This should only happen on Windows. Other OSs work properly. |
This issue occurred in Ubuntu also. |
Code does find these in Linux and OS X. Please try it one more time in Linux and confirm that it doesn't work. If that's the case, it's a separate issue. |
Yes, I confirmed it again, and I got same result. I think that |
getUserEnvironment() exists for the specific purpose that Code cannot rely on inheriting the environment from its parent process. It spawns a shell and reads the environment from it. In Linux, what do you get when you run |
Ok, I checked starman@blue3:~$ $SHELL -ilc env
:
:
SHELL=/bin/bash
:
:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
:
:
NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist
NVM_IOJS_ORG_MIRROR=https://iojs.org/dist
:
:
starman@blue3:~$ printenv PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
starman@blue3:~$ echo $0
/bin/bash Of course starman@blue3:~$ nvm use v4.2.1
Now using node v4.2.1 (npm v2.14.7)
starman@blue3:~$ gulp -v
[18:06:56] CLI version 3.9.0
starman@blue3:~$ printenv PATH
/home/starman/.nvm/versions/node/v4.2.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
So, the point of this issue is NOT that these paths are not already added to |
Now here's what I don't understand. We just have to figure out what is different in your system that makes it not work. Where did nvm configure itself in your system? |
Yes, I think that you might set Anyway, The paths may be already added to |
Maybe, does your system have a default node? (node that was installed without nvm) |
I see. So, when you spawn a shell in your system you don't have a |
In some cases, Yes. |
Got it. I argue your situation doesn't happen often. People usually either have node installed globally or just have a default node set up in nvm. I suggest you do the same. An environment variable setup in Another alternative would be to use a specific node as the task command and point it to the gulp or grunt entrypoints inside the |
Ok. So, my English is very poor. I couldn't explain well, but you interacted very patiently and kindly. Thank you 😃 |
Thanks for your ideas and feedback! |
I'm still a little bit confused by the resolution here. Are you saying users that use nvm must launch VS Code via the terminal in order to have it use the nvm version of node? This is currently the way I have to launch VS Code on OSX to have it use the nvm version. |
@vprasanth, no. @anseki seems to not have a |
Hi @vprasanth, |
@joaomoreno @anseki sweet thanks! I didn't even know I could do that. I was using |
@joaomoreno - It would be great if VS Code ran |
What do you mean by running a node script? Where does this happen? |
All of the tools, Gulp, Grunt, UglifyJS, mentioned by the OP in this issue are node.js scripts. Since there is now a range of node.js runtime versions available with breaking changes between them, different projects that I work on use different versions. NVM as a tool is great for selecting a version for a particular project, and with the So for a concrete example, in the
The protractor tool is a node.js script that will currently be run under the default installation of node.js on the system. But if this project requires a different version of node in order to run the protractor script it is stuffed. Does that make sense? |
Here's how you can do it, at least for debugging:
#!/bin/zsh
source ~/.zshrc
nvm run $* It isn't a great experience, but we don't want to hardcode the notion of |
@joaomoreno thanks for the workaround. I'll take a look at the node-debug extension people. |
This issue also affects me. On Ubuntu 16.04 using nvm, I use a node module that checks for Would it be possible to add a custom path to VSC's user settings? We currently have: "git.path": null,
"php.validate.executablePath": null, Perhaps it would help to add a custom path for |
Hi @theetrain, For your information, this is my solution:
|
Or you could execute this before opening vs code |
The following worked for me too:
It would be nice if there is an easier way to switch node versions while you are in the IDE. |
The workaround by @joaomoreno worked well for me. I was using bash instead of zsh so I posted the updated script and details over on my blog: NVM and VS Code for anyone who's interested. |
After reading this, I got the impression that it would make sense to add "nvm" support to node-debug. So something like |
The above approach ( I've also being specifying the node executable too for the times that I forget to launch code via a terminal. For example: {
"type": "node",
"request": "launch",
"name": "generator scribble",
"runtimeExecutable": "${env:HOME}/.nvm/versions/node/v4.6.1/bin/node",
"program": "${workspaceRoot}/generators/index.js"
} |
Thanks @biddster |
Thanks @biddster I just went into my command line, did a |
(Sorry guys, pretty long discussion, maybe I missed the answer to my question) My environment:
So when I run my Node.js project in debug mode in Visual Studio Code (Code was opened via icon) I get an error "Cannot find runtime 'node' on PATH. Make sure to have 'node' installed.". I checked process.env in developer tools and there is no nvm mention. While integrated terminal knows But when I run Code from terminal it works fine and process.env has all nvm related stuff. Not sure if I should create a separate issue as there were many issues on this topic but I can not find a clear answer why Code running from GUI does not set nvm variables correctly. Thank you. |
Similar issues to @gg-berdzenishvili. I have Linux Mint 18.2 with bash. nvm is sourced in ~/.bashrc but when launching code from the menu or desktop, any extension that relies on node doesn't function correctly such as flow-for-vscode will show an error that node cannot be found in the path. As others have said, I'm sure I could hack around and make a shell script to set the env variables and then launch code, but I feel this is something one would expect to work out of the box. With the large number of people using nvm to manage node installs, it may be worth it to better the support for nvm out of the box. |
I found a way to use |
Hi, thank you for great app.
So, I hope VS Code sets specified environment variables when it starts.
I use a NodeJS Version Manager such as nvm, then a path to NodeJS is not added to
PATH
until nvm do it. (AlsoNODE_PATH
,NODE_HOME
, etc.)That is, CLI of modules such as Gulp, Grunt, UglifyJS, etc. are not work as Task of VS Code. (VS Code can't find out these.)
When I add to
PATH
a path to these CLIs such as/path/to/nvm/v4.2.4
and callcode
command, these Tasks work fine. Or when I add a following line toVS Code DIRECTORY/bin/code.js
.But, When VS Code is started from launcher such as Windows Start Menu, these are not work because
Code.exe
is called directly.As everyone knows, NodeJS is updated frequently. A better solution I think is that VS Code sets environment variables written in
settings.json
that was specified by user. Or user is given a chance such as "Startup Script(or Command)" to do something.The text was updated successfully, but these errors were encountered: