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

Using "ts-node" instead of "node" by default for ts files breaks the "--inspect" flag #1565

Closed
mefcorvi opened this issue May 6, 2019 · 15 comments
Labels

Comments

@mefcorvi
Copy link

mefcorvi commented May 6, 2019

  • nodemon -v: 1.19.0
  • node -v: 12.0
  • Operating system/terminal environment: Alpine
  • Using Docker? What image: node:12-alpine
  • Command you ran: nodemon --inspect=0.0.0.0:9229 -r tsconfig-paths/register -r ts-node/register/type-check ./src/main.ts

Expected behaviour

The --inspect flag correctly passed to the node executable.

Actual behaviour

The --inspect flag passed to the ts-node executable but ts-node doesn't support that flag.

Created from PR #1552 (comment)

@mefcorvi mefcorvi changed the title Using "ts-node" instead of "node" by default for ts files has broken "--inspect" flag Using "ts-node" instead of "node" by default for ts files breaks the "--inspect" flag May 6, 2019
@remy
Copy link
Owner

remy commented May 8, 2019

This is related to #1564.

I don't use typescript at all, so you'll need to walk me through this. What is it in your command (assuming you're using node and not nodemon): --inspect=0.0.0.0:9229 -r tsconfig-paths/register -r ts-node/register/type-check ./src/main.ts that makes the .ts file compile as typescript?

@dinofx
Copy link

dinofx commented May 14, 2019

This happens for me with node 10.15. If a launch a file ending with .ts in vscode, nodemon attempts to use ts-node instead of node. But vscode appends --inspect-brk arg:

starting `ts-node -r ts-node/register --inspect-brk=8917 /Users/dino/Development/better-ts/src/index.ts`
/Users/dino/Development/better-ts/node_modules/arg/index.js:92
                                                throw err;
                                                ^

Error: Unknown or unexpected option: --inspect-brk

Our workaround was to edit the vscode launch config and override nodemon's default file mapping to force node to be used (last two lines):

			...
			"args": ["${workspaceFolder}/src/index.ts"],
			"runtimeArgs": [
				"-r",
				"ts-node/register",
				"--exec",
				"node"
			],...

@remy
Copy link
Owner

remy commented May 14, 2019

Open question: should nodemon drop the (newly added) default mapping for .ts files?

Or is there another solution?

@remy
Copy link
Owner

remy commented May 14, 2019

Is it just --inspect that could cause this problem in user workflow? Because if it is, then the mapping could be done conditionally (as I think the old .coffee handling is done using conditional logic).

@ksmithut
Copy link

Adding my use case, this is my command:

nodemon --inspect=0.0.0.0:9229 --exec 'ts-node src/index.ts'

Which outputs:

[nodemon] starting `ts-node src/index.ts --inspect=0.0.0.0:9229`

I did have some luck with the following:

nodemon --exec 'node --inspect=0.0.0.0:9229 --require ts-node/register src/index.ts'

Which attaches the debugger as expected. Seems like more of an issue with ts-node than with nodemon itself. I'm also having issues with breakpoints matching up with the lines, but that's definitely not a nodemon issue.

@stale
Copy link

stale bot commented Jun 5, 2019

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up.
Thank you for contributing <3

@stale stale bot added the stale no activity for 2 weeks label Jun 5, 2019
@taye
Copy link

taye commented Jun 6, 2019

Hi @remy. Thanks for your work on nodemon!

I'd prefer to have the option to specify exactly which modules node will require.

I think it would be reasonable to automatically add --require ts-node/register for .ts files only if no --require args are provided to nodemon. This would make nodemon easier to use with typescript files, but without getting in the way of more customised setups.

@stale stale bot removed the stale no activity for 2 weeks label Jun 6, 2019
@remy
Copy link
Owner

remy commented Jun 6, 2019 via email

@stale
Copy link

stale bot commented Jun 20, 2019

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up.
Thank you for contributing <3

@stale stale bot added the stale no activity for 2 weeks label Jun 20, 2019
@taye
Copy link

taye commented Jun 20, 2019 via email

@stale stale bot removed the stale no activity for 2 weeks label Jun 20, 2019
@stale
Copy link

stale bot commented Jul 4, 2019

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up.
Thank you for contributing <3

@stale stale bot added the stale no activity for 2 weeks label Jul 4, 2019
@stale stale bot closed this as completed Jul 11, 2019
taye added a commit to taye/interact.js that referenced this issue Jul 13, 2019
@FernandoGIntersog
Copy link

Adding my use case, this is my command:

nodemon --inspect=0.0.0.0:9229 --exec 'ts-node src/index.ts'

Which outputs:

[nodemon] starting `ts-node src/index.ts --inspect=0.0.0.0:9229`

I did have some luck with the following:

nodemon --exec 'node --inspect=0.0.0.0:9229 --require ts-node/register src/index.ts'

Which attaches the debugger as expected. Seems like more of an issue with ts-node than with nodemon itself. I'm also having issues with breakpoints matching up with the lines, but that's definitely not a nodemon issue.

worked for me

@cecilemuller
Copy link

Another option is using execMap in package.json:

  "nodemonConfig": {
    "execMap": {
      "ts": "node --require ts-node/register/transpile-only"
    }
  }

Now nodemon --inspect-brk=9229 src/example.ts runs node --require ts-node/register/transpile-only --inspect-brk=9229 src/example.ts.

@emafriedrich
Copy link

Adding my use case, this is my command:

nodemon --inspect=0.0.0.0:9229 --exec 'ts-node src/index.ts'

Which outputs:

[nodemon] starting `ts-node src/index.ts --inspect=0.0.0.0:9229`

I did have some luck with the following:

nodemon --exec 'node --inspect=0.0.0.0:9229 --require ts-node/register src/index.ts'

Which attaches the debugger as expected. Seems like more of an issue with ts-node than with nodemon itself. I'm also having issues with breakpoints matching up with the lines, but that's definitely not a nodemon issue.

works great!

@agkairos
Copy link

--require ts-node/register

2022 and it helped me!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants