Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ORESoftware opened this issue Dec 3, 2017 · 15 comments
Closed

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

ORESoftware opened this issue Dec 3, 2017 · 15 comments

Comments

@ORESoftware
Copy link

ORESoftware commented Dec 3, 2017

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.

@ORESoftware ORESoftware changed the title How to launch in debug mode Support Q: How to launch in debug mode Dec 3, 2017
@ORESoftware ORESoftware changed the title Support Q: How to launch in debug mode Bug/feature: ts-node should work with NODE_OPTIONS Dec 4, 2017
@ORESoftware
Copy link
Author

See this issue for reference: nodejs/help#1007

@stelcheck
Copy link
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.

@ORESoftware
Copy link
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.

@stelcheck
Copy link
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.

@ORESoftware
Copy link
Author

ORESoftware commented Dec 10, 2017

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.

@stelcheck
Copy link
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.

@stelcheck
Copy link
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?

stelcheck added a commit to stelcheck/ts-node that referenced this issue Dec 10, 2017
This will remap all `TS_NODE_` environment to
`NODE_` environment variables for the child process
being spawned.

Fixes TypeStrong#465 TypeStrong#471
@stelcheck
Copy link
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.

@ORESoftware
Copy link
Author

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

@ORESoftware
Copy link
Author

ORESoftware commented Dec 12, 2017

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

@blakeembrey
Copy link
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.

@ORESoftware
Copy link
Author

ORESoftware commented Dec 14, 2017

@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.

stelcheck added a commit to stelcheck/ts-node that referenced this issue Dec 15, 2017
This will remap all `TS_NODE_` environment to
`NODE_` environment variables for the child process
being spawned.

Fixes TypeStrong#471
@stelcheck
Copy link
Contributor

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

@ORESoftware
Copy link
Author

cool I am all for anything that werks

@blakeembrey
Copy link
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
Projects
None yet
Development

No branches or pull requests

3 participants