process.send is conditionally defined in Node.js
Mia Lopez
For whatever reason, in Node.js, the function process.send is defined in some environments but not defined in others. For instance, when I fork a child process from a parent process in Node.js like so:
//parent process
var cp = require('child_process');
var k = cp.fork('./child.js',['arg1','arg2','arg3']);
k.send('fail'); //k.send is defined...
process.send("ok, let's try this..."); //process.send is NOT definedinside the child process:
//child.js
process.send('message'); //process.send is defined, and will send a message to the parent process abovewhy is process.send conditionally defined in some Node.js processes but not others? Seems like a poor design decision by Node.js architects.
The only way I know how to get around this is:
if (typeof process.send === 'function') { process.send('what I want to send');
} 4 2 Answers
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" to communicate, so its not there. From the docs:
In the child the process object will have a send() method, and process will emit objects each time it receives a message on its channel.
To avoid having to "litter the code with conditionals", a temporary solution might be to just put a "noop" function in its place at the top of any "root" files you might be spawning processes from:
process.send = process.send || function () {}; 8 Workaround for Sapper & Svelte usage:
Basically, this error can be received in flow when you provided SAPPER_EXPORT variable in your environment.
More details about issue: