Search code examples
node.jstypescriptdebuggingnodemonts-node

Why does the node inspector not start when I am using nodemon and ts-node?


I have a simple node server written in typescript. My package.json is configured as:

"scripts": {
  "build": "tsc",
  "dev": "nodemon --watch src/**/* -e ts,json --exec ts-node ./src/server.ts",
  "debug": "nodemon  --verbose  --watch src/**/* -e ts,json --exec ts-node --inspect ./src/server.ts"
},

When I run npm run dev nodemon will launch the server and restart it when any changes are made.

[02/28/18 20:45:53]  npm run dev

> [email protected] dev C:\Users\joe\pq\pq-api
> nodemon --watch src/**/* -e ts,json --exec ts-node ./src/server.ts

[nodemon] 1.15.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: src/**/*
[nodemon] starting `ts-node ./src/server.ts`
initializing config to development
info: PQ-API running on port 3000

However, when I run npm run debug (so I can attach a debugger) It looks like it begins to start, but just hangs forever

[02/28/18 20:39:30]  npm run debug

> [email protected] debug C:\Users\joe\pq\pq-api
> nodemon  --verbose  --watch src/**/* -e ts,json --exec ts-node --inspect ./src/server.ts

[nodemon] 1.15.1
[nodemon] to restart at any time, enter `rs`
[nodemon] or send SIGHUP to 10156 to restart
[nodemon] watching: src/**/*
[nodemon] watching extensions: ts,json
[nodemon] starting `ts-node --inspect ./src/server.ts`
[nodemon] spawning
[nodemon] child pid: 13344
[nodemon] watching 12 files

That is all the output has. The script is never executed; the server never starts up, and the inspector is never available to connect to.

node 8.94
nodemon 1.15.1
ts-node 5.0.0
typescript 2.7.2


Solution

  • With ts-node 5.0.0 you no longer pass the --inspect flag the same way. The suggested way is node --inspect -r ts-node/register path/to/ts. For example:

    nodemon --watch src/**/* -e ts,json --exec node --inspect-brk -r ts-node/register src/app.ts

    see https://github.com/TypeStrong/ts-node/issues/537