babel: process.send is not a function in child spawned with babel-node (ipc doesn't work)
Input Code
spawn.js
:
import {spawn} from 'child_process'
spawn('babel-node', ['child.js'], {
stdio: [0, 1, 2, 'ipc']
})
child.js
:
process.send({hello: 'world'})
Babel Configuration (.bablerc, package.json, cli command)
{
"presets": ["es2015", "stage-1"]
}
Expected Behavior
No errors are thrown when I spawn child.js
with node
.
Current Behavior
When I spawn child.js
with babel-node
, I see the following error in the console:
child.js:3
process.send({ hello: 'world' });
^
TypeError: process.send is not a function
at Object.<anonymous> (/Users/andy/smart-restart/child.js:1:9)
at Module._compile (module.js:413:34)
at loader (/Users/andy/.nvm/versions/node/v5.12.0/lib/node_modules/babel-cli/node_modules/babel-register/lib/node.js:146:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/andy/.nvm/versions/node/v5.12.0/lib/node_modules/babel-cli/node_modules/babel-register/lib/node.js:156:7)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at /Users/andy/.nvm/versions/node/v5.12.0/lib/node_modules/babel-cli/lib/_babel-node.js:151:24
at Object.<anonymous> (/Users/andy/.nvm/versions/node/v5.12.0/lib/node_modules/babel-cli/lib/_babel-node.js:152:7)
at Module._compile (module.js:413:34)
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
software | version |
---|---|
Babel | 6.14.0 |
node | 5.12.0 |
npm | 3.8.6 |
Operating System | OS X 10.11.6 |
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 14
- Comments: 23 (9 by maintainers)
Commits related to this issue
- try to use IPC to send message (not possible due to https://github.com/babel/babel/issues/4554) — committed to qawolf/qawolf by jperl 4 years ago
- try to use IPC to send message (not possible due to https://github.com/babel/babel/issues/4554) — committed to qawolf/qawolf by jperl 4 years ago
@emahuni that misses the point,
process.send
is 100% supposed to be available when the process was spawned with an ipc channel, but this isn’t working when the process was spawned frombabel-node
.process.send = process.send || () => {}
isn’t a workaround because we need to communicate with the parent process, not just preventprocess.send()
from throwing an error.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 🙂
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.
This is still an issue and
kexec
doesn’t fix it as it only deals with the default 3 file descriptors.