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

adding support for a custom node path or setting version with NVM #5456

Closed
oriSomething opened this issue Apr 18, 2016 · 11 comments
Closed

adding support for a custom node path or setting version with NVM #5456

oriSomething opened this issue Apr 18, 2016 · 11 comments
Assignees
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality

Comments

@oriSomething
Copy link

adding support for a custom node path or setting version with NVM. currently it only works with default alias of NVM. since the workspace i'm using it would be a hassle every time to change the default alias of NVM for every project.

  • VSCode Version:
    1.0.0
  • OS Version:
    OS X 10.10.5
@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Apr 18, 2016
@dbaeumer
Copy link
Member

@oriSomething can you please describe the use case? Doyou need this for debugging ?

@oriSomething
Copy link
Author

yes.
i'm trying to debug... but then i get the wrong node version. because in my computer i need by default to use older version (v0.12.x) of node (need of most of the projects), and this specific project depends on capabilities of node >= v4.
in the debugger i see messages of version 0.12.13 while i need it to be version 4. the only option i have is to change in NVM to default "alias" of the version i need for VSCode.
because i cannot bump the node version to the whole of the other projects, and sometimes i need to work at both at them at once it makes this process frustrate.

@dbaeumer dbaeumer added debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality and removed info-needed Issue requires more information from poster labels Apr 18, 2016
@isidorn isidorn assigned weinand and unassigned isidorn Apr 18, 2016
@weinand
Copy link
Contributor

weinand commented Apr 18, 2016

@oriSomething you can set the "runtimeExecutable" of your launch config to the desired node.js version.

@weinand weinand closed this as completed Apr 18, 2016
@jefffriesen
Copy link

I don't know if this is a question or feature request. To get the node version when we use nvm I use in the terminal:

which node

The output I can paste in runtimeExecutable property of launch.json. I want to do something like this in launch.json:

"runtimeExecutable": "${`which node`}"

So it picks up which version of node I'm using. But that doesn't work when trying to debug.

Attribute 'runtimeExecutable' is not absolute ('${which node}'); consider adding '${workspaceRoot}/' as a prefix to make it absolute.

Can I make this work? Also, wouldn't that be a sane default?

@weinand
Copy link
Contributor

weinand commented Sep 13, 2016

@jefffriesen variable substitution for ${...} in launch.json attributes does not use a shell. So the shell syntax 'which node' does not work at all. VS Code sees it as a variable with name 'which node'.

But I do not see a reason why you want to use "runtimeExecutable": "${'which node'}" at all.

which node just returns the node that is available through your PATH. If you do not specify "runtimeExecutable", VS Code will just use the 'node' that is available through the PATH which is by definition identical to what you want to achieve.

In the September release you will be able to use "runtimeExecutable": "node" so we will lift the requirement to use an absolute path.

@jefffriesen
Copy link

@weinand I see what you're saying. When I first tried the debugger using nvm to set the node version, I got an error about node not being found (I didn't copy the error). I took what I got from which node in the terminal and added it to runtimeExecutable inside launch.json, which worked. That's why I tried to use the terminal command which node in runtimeExecutable. Now after your message I deleted the path in runtimeExecutable, restarted vscode and the debugger still works.

So I don't know what happened and can't repeat it. Thanks.

@weinand
Copy link
Contributor

weinand commented Sep 13, 2016

@jefffriesen in previous releases VS Code had a bug that would prevent the PATH environment variable from being correctly propagated to the place where we called "node". In this case node was not found and a workaround was to set runtimeExecutable to the absolute path of node. Since this problem has been fixed, setting runtimeExecutable is no longer necessary.

@jefffriesen
Copy link

Ok, good to know.

I don't know why I got that error. It was the first time running the debugger. It's possible that I hadn't set nvm yet in the terminal, so no Node version was found. But that's usually the first thing I do when opening a terminal. Either way, I'm good. Thanks

@seanfisher
Copy link

seanfisher commented Apr 26, 2017

I used a workaround listed in #1895 to have VS Code use the NVM managed version of node in the .nvmrc file. I wrote up the details @ NVM and VS Code if you're interested.

@oriSomething
Copy link
Author

@seanfisher I'll read about it. Thanks!

@z-vr
Copy link

z-vr commented Aug 30, 2017

borrowing @seanfisher's method, it's

node.sh

#!/bin/bash

[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm

nvm run $*

.nvmrc

4

launch.json

        {
            "type": "node",
            "request": "launch",
            "name": "Launch program",
            "program": "${workspaceRoot}/index",
            "runtimeExecutable": "${workspaceRoot}/node.sh",
            "protocol": "legacy"
        },

this is enough (if NVM_DIR is exported, which it should be). make sure to specify legacy protocol for Node 4.

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

7 participants