Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't get correct message from child process. #325

Open
thomasyxy opened this issue Sep 30, 2022 · 1 comment
Open

can't get correct message from child process. #325

thomasyxy opened this issue Sep 30, 2022 · 1 comment

Comments

@thomasyxy
Copy link

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

@karlwestin
Copy link

karlwestin commented Jan 27, 2023

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 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants