can't get correct message from child process.
thomasyxy opened this issue · comments
Issue description
Context
*mac OS M1, ts-node-dev@2.0.0
parent.js
`const path = require('path');
const { fork } = require('child_process');
const forked = fork(path.join(__dirname, './child.js'));
forked.on('message', (msg) => {
console.log('Message from child', msg);
});
forked.send({ hello: 'world' });`
child.js
`process.on('message', (msg) => {
console.log('Message from parent:', msg);
});
let counter = 0;
setInterval(() => {
process.send({ counter: counter++ });
}, 1000);
`
ts-node-dev --respawn --rs parent.js
I've had this issue too
Your example reproduces the issue very well
The --fork
flag does not seem to help:
ts-node-dev --respawn --rs --fork parent.js
Trying to learn about the child process system but it's quite tricky indeed 😅