Ts-node: debug-wise args are not honored

Created on 8 Feb 2018  路  7Comments  路  Source: TypeStrong/ts-node

  • nodemon -v: 1.14.12
  • node -v: 8.9.4
  • ts-node -v: 4.1.0
  • Operating system/terminal environment: Windows 10 x64
  • Command you ran:

nodemon with the following nodemon.json:

{
    "verbose": true,
    "watch": [
        "src"
    ],
    "ext": "ts",
    "exec": "{{pwd}}/node_modules/.bin/ts-node ./src/index.ts --project ./tsconfig.development.json --inspect=5858 --inspect-brk"
}

Expected behaviour

--inspect=5858 --inspect-brk are passed to node and one can connect with debugger

Actual behaviour

--inspect=5858 --inspect-brk are not passed to node and one can't connect with debugger

terminal output:

[nodemon] 1.14.12
[nodemon] reading config .\nodemon.json
[nodemon] to restart at any time, enter `rs`
[nodemon] or send SIGHUP to 22156 to restart
[nodemon] watching: C:\Dev\node-typescript-vscode\src/**/*
[nodemon] watching extensions: ts
[nodemon] starting `C:\Dev\node-typescript-vscode/node_modules/.bin/ts-node ./src/index.ts --project ./tsconfig.development.json --inspect=5858 --inspect-brk`
[nodemon] spawning
[nodemon] child pid: 11272
[nodemon] watching 2 files

Steps to reproduce

  1. clone https://github.com/deilan-issues-samples/ts-node-issue-531
  2. yarn install or npm install
  3. yarn run serve:debug or npm run serve:debug

    4. launch Attach to nodemon VS Code debug configuration

bug wontfix

Most helpful comment

Closing with https://github.com/TypeStrong/ts-node/pull/536. I recommend node -r ts-node/register for all advanced node.js use-cases and flags.

All 7 comments

Continuation of discussion of remy/nodemon#1250 and specifically https://github.com/remy/nodemon/issues/1250#issuecomment-364084892.

Yes, I was going crazy for a file. I thought it was just me. Actually, I am also running nodemon but I took this out of the equation. So I execute

ts-node ./src/index.ts --inspect-brk=5860

And the same thing, it never waits for the debugger to be attached and prints out to the console the console.log that I made. I also had a breakpoint on the console.log.

Sorry, probably worth mentioning that i am on a MAC

and

ts-node v4.1.0
node v8.9.1
typescript v2.7.1

Ok, I think i have a workaround

You can execute it like this

node --inspect-brk=5858 --require ts-node/register ./src/index.ts

so you can create your nodemon.json file and do this, (create multiple nodemon.json files if you like - I have 1 for inspect and 1 for inspect-brk)

{
  "watch": ["src"],
  "ext": "ts",
  "ignore": ["src/**/*.spec.ts"],
  "exec": "node --inspect-brk=5858 --require ts-node/register ./src/index.ts"
}

Hope that helps.

So this trick here is not to run ts-node direct but to load via node.

@appsolutegeek Thanks for the workaround! Unfortunately it's not a complete solution because there's a case when third-party tools pass these args to the ending dynamically, e. g. Visual Studio Code debugger.

I'd recommend using node --require with flags. I'm going to deprecate this current usage, the hacks are just too taxing on me to maintain. Can you describe why that doesn't work for Visual Studio Code debugger?

Closing with https://github.com/TypeStrong/ts-node/pull/536. I recommend node -r ts-node/register for all advanced node.js use-cases and flags.

Was this page helpful?
0 / 5 - 0 ratings