Closed
Description
Search Terms
child process, fork, esm, loader, brotli, config, exec argv, exec path
Expected Behavior
Similar to when running with node --loader ts-node/esm
or plain node
, the main process should be able to fork and execute other NodeJS scripts (not necessarily another TS file).
When vanilla Node executes, the execArgv
never contains the script entry-point, so that the fork
can set the new script that is intended to be run.
Actual Behavior
Using the builtin NodeJS fork
method does not work when running with ts-node --esm
because the process.execPath
and process.execArgv
contain the brotli-base64 encoded config and the custom loader script. This is resulting in the same script being executed all the time, going into an infinite loop based on the script.
Steps to reproduce the problem
- Create a TS ESM file e.g.
.mts
- Use NodeJS
fork
and try to load another file, e.g. a plainworker.mjs
file - Observe that the worker script is never executing, but instead the orignal
.mts
file is executed again, and so on.
Minimal reproduction
- Clone https://github.com/devversion/ts-node-esm-fork/tree/main
- Run
yarn test
Specifications
ts-node v10.8.1
node v16.14.2
compiler v4.7.4
Done in 0.35s.
- Linux 64bit
Metadata
Metadata
Assignees
Labels
No labels