When I'm sending a message from parent.js to child.js in commonJs syntax then it works. In parent.js I have
//parent.js
const cp = require('child_process');
let child = cp.fork('./child.js');
child.on('message', (message) =>{
console.log('Parent got message: '+message);
});
// parent sends a message
child.send('Parent sends message');
in child.js I have:
// child.js
process.on('message', (m) => {
console.log('child got message:', m);
process.send('child sends message');
});
everything works and in console I'm getting:
child got message: Parent sends message
Parent got message: child sends message
but it stops working when I use ES6 import syntax:
import * as cp from 'child_process';
Do I'm doing something wrong, or this is a nodejs bug?
My node version is 16.13.2 Under not working I mean cursor in terminal is blinking, but I'm not getting any message and I'm not getting any error.