ts-node icon indicating copy to clipboard operation
ts-node copied to clipboard

Add self as preload script, to load in worker_threads and child processes.

Open cspotcode opened this issue 4 years ago • 3 comments

When user runs ts-node ./index.ts and the code spawns worker_threads and/or child_processes, these should also be able to require() .ts files.

This already happens with node --require ts-node/register, since that's inherited by child processes and worker threads.

Should we make our ts-node bin entrypoint behave the same way?


yarn uses NODE_OPTIONS='--require .pnp.js' to hook their PnP API into the runtime. nyc uses some sort of child_process.spawn monkey-patching, but they also don't support worker_threads. Why don't they use NODE_OPTIONS?

https://github.com/nodejs/node/issues/36531 https://github.com/nodejs/node/issues/29117

Are there performance concerns? Can we avoid child processes/threads re-resolving tsconfig when the parent has already done so? By passing the necessary config via an env var, or maybe prepending a --require /tmp/ts-node-config-497f86.cjs?

cspotcode avatar Dec 16 '20 15:12 cspotcode

Curious if there's any updates regarding this issue almost a year later, we've used ts-node exclusively in production for awhile, but we're having to move away from it as the worker_threads implementation can't find a .js file that doesn't exist, requiring us to build and run from node directly.

ChristianTucker avatar Sep 27 '21 17:09 ChristianTucker

Is there a pull request for this? Are you able to send one to be reviewed? Have you tried the recommended approaches above? Those approaches already work with ts-node in worker threads today. If you've tried them, did they work, or were there blockers?

Answers to these questions will help to triage this issue.

cspotcode avatar Sep 27 '21 18:09 cspotcode

@ChristianTucker any update? Would appreciate your assistance to properly prioritize this issue.

cspotcode avatar Sep 28 '21 16:09 cspotcode