node-cross-spawn
node-cross-spawn copied to clipboard
EBADF: bad file descriptor, uv_pipe_open on windows with ipc
Stack trace:
Hey guys, I have a problem with child_process on windows while using ipc so I asked a question.
I found this module to solve it but the same error happens.
The problem occurs on windows, spawning something in js (e.g. npm or child.js) and with ipc option. The ipc is required as some of the commands will be my commands and I need to communicate with it.
I am not sure what I am doing wrong. Thanks for help.
Code:
const spawn = require('cross-spawn');
const cmd = spawn('npm', ['-v'], {shell: true, stdio: ['inherit', 'inherit', 'inherit', 'ipc'] } ));
cmd.on('message', (msg) => console.log({msg}));
cmd.on('close', (code) => console.log({code}));
Stack trace:
child_process.js:122
p.open(fd);
^
Error: EBADF: bad file descriptor, uv_pipe_open
at Object._forkChild (child_process.js:122:5)
at setupChildProcessIpcChannel (internal/bootstrap/pre_execution.js:329:30)
at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:54:3)
at internal/main/run_main_module.js:7:1 {
errno: -4083,
code: 'EBADF',
syscall: 'uv_pipe_open'
}
child_process.js:122
p.open(fd);
^
Error: EBADF: bad file descriptor, uv_pipe_open
←[90m at Object._forkChild (child_process.js:122:5)←[39m
←[90m at setupChildProcessIpcChannel (internal/bootstrap/pre_execution.js:329
:30)←[39m
←[90m at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:54:3
)←[39m
←[90m at internal/main/run_main_module.js:7:1←[39m {
errno: ←[33m-4083←[39m,
code: ←[32m'EBADF'←[39m,
syscall: ←[32m'uv_pipe_open'←[39m
}
I have the same error using
serverProcess = crossSpawn('node', [
someScriptFullPath,
'--port', serverPort,
], {
stdio: [null, null, null, 'ipc'],
});
on node 16, with nodist
I believe (in my case), that nodist is the culprit because the shim is in go, and docs says
Accessing the IPC channel fd in any way other than process.send() or using the IPC channel with a child process that is not a Node.js instance is not supported.
so it probably breaks here.
a workaround is to use fork
which does not use the shim