VS Code, change NodeJS version for debugger

2019-04-04 10:22发布

问题:

I want to change NodeJS version from 4.5.0 to 7.7.2 for VS Code specifically for different projects. I am using nvm on Mac, and I have two versions stated above. They are for different projects.

Even though I can change from terminal with nvm, VS Code uses default version. I need to change the default version every time and completely restart the VSCode. Is there a way to alter configuration so it picks up the version I wanted both for in-app terminal and for running project?

回答1:

After VS Code 1.21, there is a better solution than the original answer.

You can set "runtimeVersion": "7.7.2" and if you have nvm/nvs installed, it will be able to find that version of Node. Details: https://code.visualstudio.com/updates/v1_21#_node-debugging

--- Original answer ---

In your launch config, you can set a path to a Node executable from nvm like this: "runtimeExecutable": "/Users/me/.nvm/versions/node/v7.7.1/bin/node"