如何为VS Code扩展设置默认Node读取路径?
Hey there, I’ve run into this exact issue before—nvm’s Node.js setup can sometimes throw off VS Code’s extensions because the editor doesn’t automatically pick up the nvm-managed paths. Let’s walk through how to get jsHint, Flow, JavaScript Standard Style, and others working correctly with your setup.
Why This Happens
VS Code usually defaults to the system-wide Node.js installation (if you have one), but your Node and npm are located in the nvm directory at /home/putrapc/.nvm/versions/node/v8.9.4/bin/. The extensions can’t find these paths unless we explicitly tell VS Code where to look.
Step 1: Point VS Code to Your NVM Node.js Path
There are two reliable ways to do this:
Option A: Configure via Settings JSON
- Open VS Code’s settings by pressing
Ctrl+,(Windows/Linux) orCmd+,(Mac). - Search for nodePath in the settings search bar.
- Under the "Node Path" setting, enter your nvm Node.js path:
Alternatively, open the raw settings JSON file by pressing/home/putrapc/.nvm/versions/node/v8.9.4/bin/nodeCtrl+Shift+P(orCmd+Shift+P), typing "Open Settings (JSON)", and adding this line:"nodePath": "/home/putrapc/.nvm/versions/node/v8.9.4/bin/node"
Option B: Launch VS Code from a Terminal with NVM Activated
This ensures VS Code inherits your terminal’s environment variables (including the correct Node/npm paths):
- Open your terminal and activate your nvm version first:
nvm use v8.9.4 - Navigate to your project directory, then launch VS Code with:
code .
Step 2: Configure Individual Extensions (If Needed)
If the global Node path fix doesn’t resolve all issues, you can specify paths directly for each problematic extension:
- jsHint: Add this to your settings JSON:
"jshint.nodePath": "/home/putrapc/.nvm/versions/node/v8.9.4/bin/node" - Flow: If you installed Flow globally via npm, set its path:
"flow.pathToFlow": "/home/putrapc/.nvm/versions/node/v8.9.4/bin/flow" - JavaScript Standard Style: Point it to your nvm Node:
"standard.nodePath": "/home/putrapc/.nvm/versions/node/v8.9.4/bin/node"
Step 3: Verify the Fix
- Open the VS Code integrated terminal (
Ctrl+orCmd+). - Run these commands to confirm the paths are correct:
Both should output your nvm paths (which node which npm/home/putrapc/.nvm/versions/node/v8.9.4/bin/nodeand/home/putrapc/.nvm/versions/node/v8.9.4/bin/npm). - Restart VS Code and check if the error notifications are gone.
Bonus Tip: Set a Default NVM Version
To avoid having to run nvm use v8.9.4 every time, set this version as your default:
nvm alias default v8.9.4
Now every time you open a terminal, this Node version will be activated automatically—making it easier to launch VS Code correctly later.
内容的提问来源于stack exchange,提问作者mandaputtra

