要重现:
产生错误:Cannot find runtime 'node' on PATH
假设:
{
"version": "0.2.0",
"configurations": [
{
"name": "Build",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/build.js",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
"env": {
"NODE_ENV": "development"
},
"console": "internalConsole",
"sourceMaps": false
}
]
}
来自CMD和集成终端(sysnative / cmd):
PATH
包含D:/Program Files/nodejs
where node
返回D:/Program Files/nodejs/node.exe
来自Google Developer Console:
process.env.PATH
包含D:/Program Files/nodejs
D:/Program Files/nodejs/node.exe
:(function(){
const cp = require('child_process');
const env = Object.assign({}, process.env, {
ATOM_SHELL_INTERNAL_RUN_AS_NODE: '1',
ELECTRON_NO_ATTACH_CONSOLE: '1'
});
const result = cp.spawnSync('where', ['node'], {
detached: true,
stdio: ['ignore', 'pipe', process.stderr],
env,
encoding: 'utf8'
});
console.log(result.stdout);
})();
其他
此外,.NET-Core应用程序的行为相同 - 终端和cmd工作,dotnet
在路径上,但从VSCode调试器视图启动无法在路径上找到CLI工具。
附加到现有的dotnet
进程会产生不同的错误:
Please set up the launch configuration file for your application. command 'csharp.listProcess' not found
不确定是否相关,但跳转到声明的F12没有响应。
更新
我一直在做一些调试,看起来下面的代码会产生Command Failed: echo test
:
require('child_process')
.execSync('echo test', {cwd: workspaceRoot, env: process.env});
在引擎盖下,它结束了呼叫
require('child_process')
.spawnSync('cmd', ['/s', '/c', '"echo test"'], {cwd: workspaceRoot, env: process.env});
它在引擎盖下构建的命令是C:\Windows\System32\cmd.exe /s /c "echo test"
,我测试过并确实打印test
。
spawnSync
来电显示退出代码为3221225477
。
实际上,每次我使用child_process通过cmd执行某些操作时,退出代码为3221225477.不过,我可以让spawnSync启动除cmd之外的其他进程。这有效:
require('child_process')
.spawnSync('node', ['build.js'], {cwd: workspaceRoot, env: process.env});