1

I would like to use VSCode to run a program that is on my Windows computer c:\test.js using a version of node.js which is in a network folder (\\servername\folder\node.exe).

I do not want to install node.js, but just refer to the files on the network folder.

I set up the file launch.json below:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${file}",
            "runtimeExecutable": "\\\\servername\\folder\\node.exe"
        }
    ]
}

When I run test.js, VSCode gives an error Can't find Node.js binary \\servername\folder\node.exe.

I can successfully run the program if I copy node.exe to my c-drive (c:\node.exe), and change launch.json to

            "runtimeExecutable": "c:\\node.exe"

It also works to set the PATH to the network folder per How do I add environment variables to launch.json in VSCode. :

            "env": {"PATH": "\\\\servername\\folder"},
            //"runtimeExecutable": "\\\\servername\\folder\\node.exe"

I checked to ensure the path to node.exe on the network is correct.

Why can't VSCode find this file on the network, and what can I do to fix this?

mherzog
  • 1,085
  • 1
  • 12
  • 24
  • You might need to allow UNC paths via `security.allowedUNCHosts`, or simply create a local CMD/PS script to front the remote node binary. – jarmod Jul 06 '23 at 16:47
  • @jarmod, thank you for this. Great insight. In settings, I added the host `servername`. I am still getting the same error. I updated the question to reflect this. – mherzog Jul 07 '23 at 12:00
  • Correction: This worked after I restarted VSCode. This fixed the issue. Disabling checking UNCHosts also works. @jarmod, if you post this as a solution, I will accept it. – mherzog Jul 07 '23 at 12:23

1 Answers1

1

This is caused by a default security mechanism introduced in VS Code v1.78.1 that prevents access to UNC paths such as \\server\resource unless they are explicitly approved.

This setting is controlled as follows:

  • add the UNC path to the VS Code security setting security.allowedUNCHosts, or
  • define a global environment variable NODE_UNC_HOST_ALLOWLIST with the backslash-separated list of hostnames to allow

You may need to restart VS Code for these changes to take effect.

You can also simply net use the remote resource to map it to a local drive identifier, in which case you don't need to allow the UNC path explicitly.

See Working with UNC paths and this question for more details.

jarmod
  • 71,565
  • 16
  • 115
  • 122