Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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 defined
inside the child process:
//child.js
process.send('message'); //process.send is defined, and will send a message to the parent process above
The only way I know how to get around this is:
if (typeof process.send === 'function') {
process.send('what I want to send');
–
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 () {};
–
–
–
–
–
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: https://github.com/Zimtir/SENT-template/issues/114
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.