Skip to content

Bug/feature: ts-node should work with NODE_OPTIONS #471

Description

@ORESoftware

This works:

ts-node --inspect-brk foo.ts  # ❤️

but this doesn't

NODE_OPTIONS="--inspect-brk" ts-node foo.ts #  💥

I think it's because ts-node starts a child process, and because of that, we get an "address already in use" error. See the Node.js help issue attached.

Just try it for yourself and you will see the problem.

Activity

  1. changed the title [-]How to launch in debug mode[/-] [+]Support Q: How to launch in debug mode[/+] on Dec 3, 2017
  2. changed the title [-]Support Q: How to launch in debug mode[/-] [+]Bug/feature: ts-node should work with NODE_OPTIONS[/+] on Dec 4, 2017
  3. ORESoftware commented on Dec 5, 2017

    @ORESoftware
    Author

    See this issue for reference: nodejs/help#1007

  4. stelcheck commented on Dec 7, 2017

    @stelcheck
    Contributor

    I think the best option would be to wrap or convert https://github.com/TypeStrong/ts-node/blob/master/src/bin.ts into a bash/cmd script.

  5. ORESoftware commented on Dec 9, 2017

    @ORESoftware
    Author

    @stelcheck I think the problem is that ts-node spawns a child process

    https://github.com/TypeStrong/ts-node/blob/master/src/bin.ts#L53

    so what we need is that spawned child process to debug on a different port than the parent process.

  6. stelcheck commented on Dec 10, 2017

    @stelcheck
    Contributor

    Why even spawn a port on the bin process? That process should not even react to NODE_OPTIONS; I can't think of a case where you'd want that as a user. This is why I was suggesting to either replace or wrap that file with a bash/sh/cmd file; these do not react to NODE_OPTIONS, and in the case of wrapping, options could then be forwarded the proper way to the spawned child process.

  7. ORESoftware commented on Dec 10, 2017

    @ORESoftware
    Author

    dude I am so confused

    this is ergonomic

    NODE_OPTIONS="--inspect-brk" ts-node foo.ts

    but it breaks... try it.

    are you suggesting something more ergonomic, or less? Sounds like the latter to me. Perhaps demo the code you are talking about.

  8. stelcheck commented on Dec 10, 2017

    @stelcheck
    Contributor

    Apologies for the confusion.

    I am suggesting a way to patch ts-node's code in a way that should solve your issue. Should we do that, running NODE_OPTIONS="--inspect-brk" should start working correctly as-is.

    And please don't call me dude.

  9. stelcheck commented on Dec 10, 2017

    @stelcheck
    Contributor

    Actually, the simplest thing might just be to introduce a TS_NODE_OPTIONS environment variable which would be passed as NODE_OPTIONS to the spawned process. @blakeembrey would that be acceptable to you?

  10. stelcheck commented on Dec 10, 2017

    @stelcheck
    Contributor

    I preemptively created a PR implementing that behavior. @ORESoftware feel free to give it a spin and let me know if this would fix your current issue.

  11. ORESoftware commented on Dec 12, 2017

    @ORESoftware
    Author

    @stelcheck yes I think that's a good idea - TS_NODE_OPTIONS seems like a good idea to me

  12. ORESoftware commented on Dec 12, 2017

    @ORESoftware
    Author

    if you could make that a command line argument as well as an env variable, that'd be nice too, but probably not that important:

    ts-node foo.ts --ts-node-options="--inspect-brk --harmony"

    I really just need one or the other, but both would make me happy too

  13. blakeembrey commented on Dec 14, 2017

    @blakeembrey
    Member

    For now, can you use ts-node -r ts-node/register? I'm hesitant to go too much further on the different node.js shell spawning tricks in use right now.

  14. ORESoftware commented on Dec 14, 2017

    @ORESoftware
    Author

    @blakeembrey - in this case my node.js process is spawning children and I need to debug the children using Node.js exec flags, so it's not just about loading ts-node/register.

  15. added a commit that references this issue on Dec 15, 2017
    f68e6e3
  16. stelcheck commented on Dec 20, 2017

    @stelcheck
    Contributor

    #499 Would allow you to use NODE_OPTIONS off the bat instead of using TS_NODE_OPTIONS

  17. ORESoftware commented on Dec 21, 2017

    @ORESoftware
    Author

    cool I am all for anything that werks

  18. blakeembrey commented on Feb 19, 2018

    @blakeembrey
    Member

    Closing with #536 as I won't be supporting the subprocess behaviour anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions