nodemon: Using "ts-node" instead of "node" by default for ts files breaks the "--inspect" flag

  • 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 https://github.com/remy/nodemon/pull/1552#issuecomment-489697831

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 4
  • Comments: 15 (4 by maintainers)

Commits related to this issue

Most upvoted comments

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.

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.

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.