process.send is not a function in child spawned with babel-node (ipc doesn't work)

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:14
  • Comments:23 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
jedwards1211commented, Mar 1, 2020

@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 from babel-node. process.send = process.send || () => {} isn’t a workaround because we need to communicate with the parent process, not just prevent process.send() from throwing an error.

4reactions
nicolo-ribaudocommented, Oct 8, 2018

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 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

process.send is conditionally defined in Node.js - Stack Overflow
Child processes have a process.send method to communicate back with the process that spawned them, while the root process doesn't have any "parent"...
Read more >
A brand new website interface for an even better experience!
process.send is not a function in child spawned with babel-node (ipc doesn't work)
Read more >
Node.js process.send() Method - GeeksforGeeks
Example 1: First, in Parent.js, we spawn the child process. Then start listening to the child process. In Child.js, we get the message...
Read more >
Changelog - Cypress Documentation
Fixed a bug where projects using Node.js 16.17+ and 18.6+ with ES Modules and TypeScript were not working with Cypress. Fixes #22795, #23393,...
Read more >
Shell scripting with Node.js - Exploring JS
8 Working with the file system on Node.js ... 12 Running shell commands in child processes ... 12.4 Asynchronous helper functions based on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found