I have a typescript project and rather than using tsc
first, I'm just running via ts-node
directly.
In my code I need to create a child process with fork()
.
If I run code like child_process.fork('ChildProcess.ts')
and ChildProcess.ts
contains some typescript only constructs (eg: import {}
, export
, ...), then the interpreter being node
, not ts-node
, will fail.
It may be recommended to use something like child_process.exec('node ./node_modules/.bin/ts-node ChildProcess.ts)
, but I really want/need the IPC communication channel that gets set up between the parent and child processes when fork()
specifically is used.
Any ideas on how to achieve this?
Thanks!
import
andexport
aren't TypeScript-specific. They're standard JavaScript introduced in ES2015. (Node has experimental, partial support for them now via the--experimental-modules
runtime flag.) But of course, none of that helps you with true TypeScript-only features that are presumably in the file, like type annotations. :-) – Teklafork('ChildProcess.ts')
should run it with ts-node, too. Can you provide a way to replicate the problem? – Blowtorch