vscode-js-debug: Can't find Node.js binary "node" using nvm

Describe the bug

I got in the trace:

“Can’t find Node.js binary “node”: path does not exist. Make sure Node.js is installed and in your PATH, or set the “runtimeExecutable” in your launch.json”

when I run such configuration:

{
    "name": "test",
    "request": "launch",
    "type": "node",
    "program": "${workspaceFolder}/index.js",
    "trace": true
}

I use nvm to manage my node install, and the PATH env is set, so I do not want to use runtimeExecutable nor runtimeVersion or anything else that will link to a specific node version. I want to keep using the latest version of node and this managed via nvm only. Just for info, if I set runtimeExecutable or runtimeVersion it launch OK.

If I launch the js script manually in the vscode terminal it launch OK (it finds the node binary).

VS Code Version: Version: 1.62.3 Commit: ccbaa2d27e38e5afa3e5c21c1c7bef4657064247 Date: 2021-11-17T08:00:36.721Z Electron: 13.5.2 Chrome: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Linux x64 5.4.0-91-generic

JavaScript Debugger (Nightly) v2021.11.1217 (the problem is seen also on standard version of JavaScript Debugger)

nvm: 0.39.0

env
NVM_INC=/home/username/.nvm/versions/node/v16.13.1/include/node
NVM_DIR=/home/username/.nvm
NVM_CD_FLAGS=
NVM_BIN=/home/username/.nvm/versions/node/v16.13.1/bin
PATH=/home/username/.nvm/versions/node/v16.13.1/bin:/home/username/.cargo/bin:/home/username/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

The terminal is bash.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 22 (2 by maintainers)

Most upvoted comments

Ok, my solution is to completely remove the launch.json from the .vscode folder then restart VSCode

I’m started to get this error too, on the latest VSCode @ macosx with M1:

code --version
1.68.1
30d9c6cd9483b2cc586687151bcbcd635f373630
arm64

Symptoms are the same:

  • Intergrated terminal has correct path, nvm is working, node binary is there etc.

    • I also have "terminal.integrated.inheritEnv": true, but this seems have no effect on js-debug extension in any way
  • JS debugger can’t attach, because node is not in PATH - We did not find node on your PATH, so we cannot enable auto-attach in your environment.

  • In developer tools of VSCode process.env.PATH looks wrong: process.env.PATH - '/usr/bin:/bin:/usr/sbin:/sbin'

  • Setting up debug.javascript.defaultRuntimeExecutable: {} and pointing it to a node biinary also does not help.

  • Interesting that this error happens even when "debug.javascript.autoAttachFilter": "disabled".

Error message stack trace if this helps :

onDidChangeNotification | @ | workbench.desktop.main.js:802
-- | -- | --
  | (anonymous) | @ | workbench.desktop.main.js:802
  | invoke | @ | workbench.desktop.main.js:67
  | deliver | @ | workbench.desktop.main.js:67
  | fire | @ | workbench.desktop.main.js:67
  | addNotification | @ | workbench.desktop.main.js:802
  | notify | @ | workbench.desktop.main.js:1988
  | (anonymous) | @ | workbench.desktop.main.js:1724
  | _showMessage | @ | workbench.desktop.main.js:1724
  | $showMessage | @ | workbench.desktop.main.js:1724
  | _doInvokeHandler | @ | workbench.desktop.main.js:1731
  | _invokeHandler | @ | workbench.desktop.main.js:1731
  | _receiveRequest | @ | workbench.desktop.main.js:1731
  | _receiveOneMessage | @ | workbench.desktop.main.js:1731
  | (anonymous) | @ | workbench.desktop.main.js:1731
  | invoke | @ | workbench.desktop.main.js:67
  | deliver | @ | workbench.desktop.main.js:67
  | fire | @ | workbench.desktop.main.js:67
  | fire | @ | workbench.desktop.main.js:83
  | _receiveMessage | @ | workbench.desktop.main.js:83
  | (anonymous) | @ | workbench.desktop.main.js:83
  | invoke | @ | workbench.desktop.main.js:67
  | deliver | @ | workbench.desktop.main.js:67
  | fire | @ | workbench.desktop.main.js:67
  | acceptChunk | @ | workbench.desktop.main.js:83
  | (anonymous) | @ | workbench.desktop.main.js:83
  | L | @ | workbench.desktop.main.js:3181
  | emit | @ | node:events:390
  | addChunk | @ | node:internal/streams/readable:315
  | readableAddChunk | @ | node:internal/streams/readable:289
  | Show 2 more frames

in my case, I had the same issue with the process.env.PATH and i fixed adding to settings.json “debug.javascript.defaultRuntimeExecutable”: { “pwa-node”: “/path/to/.nvm/versions/node/vX.X.X/bin/node” },

Hope this helps someone !

I’m seeing this issue as well which I think is the same thing:

Version: 1.73.1 Commit: 6261075646f055b99068d3688932416f2346dd3b Date: 2022-11-09T03:54:53.913Z Electron: 19.0.17 Chromium: 102.0.5005.167 Node.js: 16.14.2 V8: 10.2.154.15-electron.0 OS: Linux x64 4.15.0-194-generic Sandboxed: No

image

Actually, in my case the problem was when “vscode-testcafe” extension calls vscode.debug.startDebugging

The basic example in first post was just to illustrate.

What is weird is that if I launch VS Code via the code CLI (typing code in a bash shell) I do not have the problem. I will use that solution as a workaround.

@adamchenwei , for me removing launch.json have no effect.

Thanks! Starting vscode through code in the terminal is a workable workaround for the moment.

I’m started to get this error too, on the latest VSCode @ macosx with M1:

code --version
1.68.1
30d9c6cd9483b2cc586687151bcbcd635f373630
arm64

Symptoms are the same:

  • Intergrated terminal has correct path, nvm is working, node binary is there etc.

    • I also have "terminal.integrated.inheritEnv": true, but this seems have no effect on js-debug extension in any way
  • JS debugger can’t attach, because node is not in PATH - We did not find node on your PATH, so we cannot enable auto-attach in your environment.

  • In developer tools of VSCode process.env.PATH looks wrong: process.env.PATH - '/usr/bin:/bin:/usr/sbin:/sbin'

  • Setting up debug.javascript.defaultRuntimeExecutable: {} and pointing it to a node biinary also does not help.

  • Interesting that this error happens even when "debug.javascript.autoAttachFilter": "disabled".

Error message stack trace if this helps :

onDidChangeNotification | @ | workbench.desktop.main.js:802
-- | -- | --
  | (anonymous) | @ | workbench.desktop.main.js:802
  | invoke | @ | workbench.desktop.main.js:67
  | deliver | @ | workbench.desktop.main.js:67
  | fire | @ | workbench.desktop.main.js:67
  | addNotification | @ | workbench.desktop.main.js:802
  | notify | @ | workbench.desktop.main.js:1988
  | (anonymous) | @ | workbench.desktop.main.js:1724
  | _showMessage | @ | workbench.desktop.main.js:1724
  | $showMessage | @ | workbench.desktop.main.js:1724
  | _doInvokeHandler | @ | workbench.desktop.main.js:1731
  | _invokeHandler | @ | workbench.desktop.main.js:1731
  | _receiveRequest | @ | workbench.desktop.main.js:1731
  | _receiveOneMessage | @ | workbench.desktop.main.js:1731
  | (anonymous) | @ | workbench.desktop.main.js:1731
  | invoke | @ | workbench.desktop.main.js:67
  | deliver | @ | workbench.desktop.main.js:67
  | fire | @ | workbench.desktop.main.js:67
  | fire | @ | workbench.desktop.main.js:83
  | _receiveMessage | @ | workbench.desktop.main.js:83
  | (anonymous) | @ | workbench.desktop.main.js:83
  | invoke | @ | workbench.desktop.main.js:67
  | deliver | @ | workbench.desktop.main.js:67
  | fire | @ | workbench.desktop.main.js:67
  | acceptChunk | @ | workbench.desktop.main.js:83
  | (anonymous) | @ | workbench.desktop.main.js:83
  | L | @ | workbench.desktop.main.js:3181
  | emit | @ | node:events:390
  | addChunk | @ | node:internal/streams/readable:315
  | readableAddChunk | @ | node:internal/streams/readable:289
  | Show 2 more frames

@tipy01 make sure also restart VS Code . and if its an extension. may want to remove or disable all extension and try again

why this ticket closed? Not sure opening program through the terminal command is a good solution

In my case with linux the problem was that i use nvm for multiple node versions, and nvm is configured in .bashrc, so it worked when i started vscode from a bash terminal, but didn’t when using the kde launcher (that obvioously is not using bash at all), so i launch vscode from the terminal, tried to automate, i’ll check latter.

Setting a default on nvm did it for me on a Mac too, thanks!

I feel like there are a lot of red-herrings in this thread.

I use Linux and bash is my default terminal. And I used NVM.

The issue was that I hadn’t set default for NVM, once I fixed that, it wasn’t until I restarted VSCode that all was fixed. NOTE: “Developer: Reload Window” does NOT work. NOTE: Adding -i to my bash args only fixed half the issue (red-herring), and was not necessary, only the VSCode restart.

Actually, in my case the problem was when “vscode-testcafe” extension calls vscode.debug.startDebugging

The basic example in first post was just to illustrate.

What is weird is that if I launch VS Code via the code CLI (typing code in a bash shell) I do not have the problem. I will use that solution as a workaround.

@adamchenwei , for me removing launch.json have no effect.

Hi @connor4312 , thank your for your answer.

Yes NVM is set as appropriate in .bashrc file like described here. I do not launch VS Code via the code CLI.

If I just launch node index.js in the VS Code terminal it launch well (it inherits the PATH).

I want to know what is the right way to set the PATH environment variable for VS Code (especially the vscode-js-debug extension) to inherit it?

This means that the PATH environment variable is not being set in a way that VS Code can inherit it. Ensure that NVM is set up in your .bashrc file or .zshrc file, as appropriate. If you launch VS Code via the code CLI, then make sure the command line environment where it’s launched from has the appropriate version in its PATH.