英文:
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:
{
"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?
答案1
得分: 1
这是由于在VS Code v1.78.1中引入的默认安全机制引起的,该机制阻止访问UNC路径,例如\\server\resource
,除非它们经过明确批准。
此设置的控制方式如下:
- 将UNC路径添加到VS Code安全设置
security.allowedUNCHosts
中,或者 - 定义一个全局环境变量
NODE_UNC_HOST_ALLOWLIST
,其中包含允许的主机名的反斜杠分隔列表
您可能需要重新启动VS Code以使这些更改生效。
您还可以简单地使用net use
命令将远程资源映射到本地驱动器标识符,这样您就不需要显式允许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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论