Home > other >  Debug a Node.js CLI tool with WebStorm; How?
Debug a Node.js CLI tool with WebStorm; How?

Time:12-22

I'm trying to create a CLI tool using TypeScript, and using WebStorm as my IDE. Try as I might, I cannot seem to get the debugging function to work. I started my Node.js adventures in CLI programming based on this tutorial. I am able to transpile the TS source by running npx tsc, and I'm able to run the resulting JS file from the CLI. I'm also able to run it from a Run Configuration in WebStorm. What I can't do is debug. I've tried setting breakpoints and running it as a Debug configuration. I've tried running it with the --inspect-brk option and a separate "Attach to Node.js/Chrome" configuration (all network addresses and ports look kosher). I've gotten it to say "Debugger attached." But it just never stops at any breakpoints in the IDE. What am I missing here?

CodePudding user response:

You need to make sure to enable sourcemaps generation when compiling Typescript to JavaScript to be able to debug your code. To get them created, add "sourceMap": true to your tsconfig.json

See https://www.jetbrains.com/help/webstorm/running-and-debugging-typescript.html for more info

  • Related