-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
process.send is not a function in child spawned with babel-node (ipc doesn't work) #4554
Comments
@jedwards1211 have you found any workaround for this issue? |
@bundacia No, I haven't figured out any way to get child process IPC to work with |
ok, I'll keep trying. For some reason I can't get plain old sockets working in node and most of the examples just use this process.send wrapper. |
As a little more context, it seems that I can't open extra file descriptors at all using spawn when spawning a babel-node process. Consider this example: // parent.js
var child_process = require('child_process')
var child = child_process.spawn("./node_modules/.bin/babel-node", ['./child.js'], {
stdio: [0, 1, 2, 'pipe'],
})
child.stdio[3].on('data', m => console.log('KID SAY (fd: 3):', m.toString())) // child.js
var fs = require('fs')
var fd3 = fs.createWriteStream(null, {fd: 3})
fd3.write('hello') OUTPUT:
If I change
|
I think I may have found the problem. the babel-node script itself calls spawn like this: https://github.com/babel/babel/blob/master/packages/babel-cli/src/babel-node.js#L84: let proc = child_process.spawn(process.argv[0], args, { stdio: "inherit" }); Using the string |
@bundacia interesting, but it only uses |
@kittens would there be major downsides to just meddling with the process' own |
Closing for inactivity, if this is still an issue we can reopened or maybe check a pr? |
This is still an issue and |
I tested the following to no success. let proc = child_process.spawn(process.argv[0], args, {
stdio: ["inherit", "inherit", "inherit", "inherit"]
}); After reading through the stdio and child_process code a bit, I have two theories.
I'd bet it's something like the 2nd theory, I'm going to cc @cjihrig and @bnoordhuis who are the |
Ben would probably know the most official way to do this, if one exists. Passing the IPC channel and the file descriptor both failed for me, but I was able to proxy the IPC channel like this. |
A+ proxy solution
…On Sun, Apr 2, 2017, 4:13 PM Colin Ihrig ***@***.***> wrote:
Ben would probably know the most official way to do this, if one exists.
Passing the IPC channel and the file descriptor both failed for me, but I
was able to proxy the IPC channel like this
<cjihrig/babel@6c1f629>
.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#4554 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AABlbuZuQwe8I3xVYsz5gb9PoqApmqmYks5rsAFUgaJpZM4KFIqL>
.
|
You have an existing ipc file descriptor that you want to recognize the child process as such? Spawn it with Note that you can't use the file descriptor in two processes at the same time, though. |
Any progress here? |
will this be fixed? |
+1 please fix or provide an alternate solution |
waiting for a fix or workaround too |
I'm not very familiar with node processes (and I don't have access to a PC), but if anyone wants to investigate this issue I'd happily review a PR. If you need help, you can join our slack channel 🙂 |
I this post's answer summarise it well https://stackoverflow.com/questions/30585540/process-send-is-conditionally-defined-in-node-js |
@emahuni that misses the point, |
Also facing this issue, and this solution has been removed from github. Any chance to get this solution back ? |
I don't think this has been mentioned, one workaround is to spawn |
This issue has been closed but the fix doesn't seem to work if the child is spawn with babel-node.
const { spawn } = require('child_process');
const child = spawn('babel-node', ['child.js'], {
stdio: ['inherit', 'inherit', 'inherit', 'ipc']
});
child.on('message', (msg) => {
console.log('received from child', msg);
});
process.send('hello');
Changing EDIT: Tested with 7.13.10 EDIT 2: Should now be working with ^7.13.13 ! 👍 |
Input Code
spawn.js
:child.js
:Babel Configuration (.bablerc, package.json, cli command)
Expected Behavior
No errors are thrown when I spawn
child.js
withnode
.Current Behavior
When I spawn
child.js
withbabel-node
, I see the following error in the console:Context
I'm the author of smart-restart. I'm trying to get it to work when spawning the supervised process with
babel-node
.Your Environment
The text was updated successfully, but these errors were encountered: