tmptplayer
tmptplayer

Reputation: 509

How to run Nodemon with TypeScript in debug mode in WebStorm

I have a very basic Express server setup with NodeJS/Express + Nodemon. I'm using WebStorm as my IDE.

When running the debug/inspect script, my application is throwing a compile-time error. Following the instructions here, and cognizant of the post here, my (simplified) package.json looks like this:

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "nodemon src/app.ts",
    "debug": "nodemon --inspect=127.0.0.1:9229 src/app.ts"
  },
"devDependencies": {
    "@types/express": "^4.17.9",
    "@types/node": "^14.14.19",
    "nodemon": "^2.0.6",
    "ts-node": "^9.1.1",
    "typescript": "^4.1.3"
  }

When I run npm run debug I receive the following error:

enter image description here

I've also tried the following, all with the same result:

Any ideas why this error is occurring?

The command npm run dev does not generate an error. Upon further investigation, nodemon automatically substitutes ts-node when targeting a .ts file. Ts-node, in turn, recommends debugging by registering ts-node and running the server with the node command.

If you need to use advanced node.js CLI arguments (e.g. --inspect), use them with node -r ts-node/register instead of the ts-node CLI.

Upvotes: 9

Views: 12806

Answers (1)

lena
lena

Reputation: 93868

You can modify your script as follows:

"debug": "nodemon --exec \"node --inspect-brk=0.0.0.0:9229 --require ts-node/register src/app.ts\""

to make sure that the --inspect-brk is passed to Node.js and not to ts-node

Upvotes: 29

Related Questions