在网络文件夹中使用node.exe运行Node.js程序。

huangapple go评论70阅读模式
英文:

Run a node.js program with node.exe in a network folder

问题

以下是要翻译的内容:

"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 https://stackoverflow.com/questions/29971572/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?"

英文:

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:

{
    &quot;version&quot;: &quot;0.2.0&quot;,
    &quot;configurations&quot;: [
        {
            &quot;type&quot;: &quot;node&quot;,
            &quot;request&quot;: &quot;launch&quot;,
            &quot;name&quot;: &quot;Launch Program&quot;,
            &quot;skipFiles&quot;: [
                &quot;&lt;node_internals&gt;/**&quot;
            ],
            &quot;program&quot;: &quot;${file}&quot;,
            &quot;runtimeExecutable&quot;: &quot;\\\\servername\\folder\\node.exe&quot;
        }
    ]
}

When I run test.js, VSCode gives an error Can&#39;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

            &quot;runtimeExecutable&quot;: &quot;c:\\node.exe&quot;

It also works to set the PATH to the network folder per https://stackoverflow.com/questions/29971572/how-do-i-add-environment-variables-to-launch-json-in-vscode. :

            &quot;env&quot;: {&quot;PATH&quot;: &quot;\\\\servername\\folder&quot;},
            //&quot;runtimeExecutable&quot;: &quot;\\\\servername\\folder\\node.exe&quot;

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?

答案1

得分: 1

这是由于在VS Code v1.78.1中引入的默认安全机制引起的,该机制阻止访问UNC路径,例如\\server\resource,除非它们经过明确批准。

此设置的控制方式如下:

  • 将UNC路径添加到VS Code安全设置security.allowedUNCHosts中,或者
  • 定义一个全局环境变量NODE_UNC_HOST_ALLOWLIST,其中包含允许的主机名的反斜杠分隔列表

您可能需要重新启动VS Code以使这些更改生效。

您还可以简单地使用net use命令将远程资源映射到本地驱动器标识符,这样您就不需要显式允许UNC路径。

有关更多详细信息,请参阅使用UNC路径此问题

英文:

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.

huangapple
  • 本文由 发表于 2023年7月7日 00:40:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76630919.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定