Problem with forking child process
cb-myroslava opened this issue · comments
Issue description
Initially I had a following setup for forking a child process (neighbour '.ts' file) using ts-node
:
import {fork} from 'child_process'
...
const workerPath = path.join(__dirname, '..', 'workers', 'calculate')
const process = fork(workerPath)
process.on('message', response => {
console.log('response', response)
})
process.send({hello: 'world'})
The worker file has ts
extension in development and js
in production.
The worker file has been returning also a response to the main process (it is a single number).
However, after switching to ts-node-dev
, I started to receive another response back from the child process:
{
"compile": "/Users/username/work/project/admin/api/src/workers/calculate.ts",
"compiledPath": "/var/folders/4d/t2sjr3s93j3bvm8c6vjm26sm0000gp/T/.…280e6bb65d555c3a57ce68c5110f7a14a9dbfad584ac45.js
}
and the actual worker file is not executed.
Is anything that I'm doing wrong?
I'm launching my application with the following command:
PORT=4000 ts-node-dev -r tsconfig-paths/register --watch api --project ./api/tsconfig.json ./api/src
Context
OS version (is it docker or host?), ts-node-dev version
MacOS BigSur 11.6
ts-node-dev: 1.1.8
Did you try to run with ts-node?
Yes, it works correctly with ts-node.
Did you try to run with --files
option enabled?
Yes, nothing changed.
Did you try to run with --debug
option enabled?
Yes, nothing changed.
Do you have a repro example (git repo) with simple steps to reproduce your problem?
I have a similar problem.
I have used Worker in a TypeScript file and I run my project using:
"start": "tsnd --inspect=0.0.0.0:9269 --ignore-watch node_modules --respawn --transpile-only -r tsconfig-paths/register src/index.ts",
But I have seen that the worker never runs doing that but in production runs properly:
"start:prod": "cross-env NODE_ENV=production node -r ts-node/register -r tsconfig-paths/register src/index.ts",
The worker start to run properly when I have removed --transpile-only
from the start
command.
Now it is running properly but I have no idea why is doing that. Someone has any idea?
Thank you very much for your time!
BR
Windows 10 Pro
ts-node: 10.1.0
ts-node-dev: 1.1.8