Skip to content

ESM flag breaks NodeJS child process fork #1812

Closed
@devversion

Description

@devversion

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

  1. Create a TS ESM file e.g. .mts
  2. Use NodeJS fork and try to load another file, e.g. a plain worker.mjs file
  3. Observe that the worker script is never executing, but instead the orignal .mts file is executed again, and so on.

Minimal reproduction

  1. Clone https://github.com/devversion/ts-node-esm-fork/tree/main
  2. 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions