14

Is there a way to pass options to node when invoking ts-node? I am trying to use an experimental feature in node and it would be swell if it would work with ts-node.

This is currently what I am doing:

ts-node ./src/utils/repl.ts -- --experimental-repl-await
unflores
  • 1,764
  • 2
  • 15
  • 35
  • 1
    [My answer](https://stackoverflow.com/a/54695790/157247), which is currently the accepted one, was wrong. [Sam's answer](https://stackoverflow.com/a/58667373/157247) is correct. I suggest switching the accepted mark to that answer (if you do, please ping me so I can delete the wrong one -- I can't delete it while it's accepted). – T.J. Crowder Feb 05 '20 at 17:34

1 Answers1

30

I got it to work this way:

node --experimental-repl-await -r ts-node/register ./src/utils/repl.ts

From the ts-node documentation:

Note: If you need to use advanced node.js CLI arguments (e.g. --inspect), use them with node -r ts-node/register instead of the ts-node CLI.


Another way to do it is to use the NODE_OPTIONS environment variable. For instance, in a *nix-style shell:

NODE_OPTIONS=--experimental-repl-await ts-node ./src/utils/repl.ts
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
Sam
  • 40,644
  • 36
  • 176
  • 219