1

I'm trying to debug my TypeScript Express app using WebStorm.

I have this debug script in package.json

"scripts": {
    ...
    "debug": "node --inspect-brk=9229 --require ts-node/register -r tsconfig-paths/register server.ts"
}

I run npm run debug in the command line and the following loads

Debugger listening on ws://127.0.0.1:9229/<somerandomid>
For help see https://nodejs.org/en/docs/inspector

Now I am able to debug from Chrome inspector by going to Chrome, type in chrome://inspect/ and server.ts would appear in Remote Target, and I can debug the TypeScript by clicking inspect. Hence I know that the problem is not my node.js configuration side.

The problem is, I can't debug when using WebStorm.

I tried the following WebStorm debug configuration:

Attach to Node.js/Chrome
Host: localhost
Port: 9229
Attach to: Chrome or Node.js > 6.3 started with --inspect

but when I debug in WebStorm the debugger keeps on saying "Connecting to localhost:9229" and nothing happens. It doesn't go to breakpoints even though I have set breakpoints in server.ts etc

I tried disabling firewall, still doesn't work. Tried using --inspect instead of --inspect-brk, still doesn't work.

What am I doing wrong, and how can I get WebStorm to debug into breakpoints using my node.js Express TypeScript configuration?

1 Answer 1

1

Works fine for me using your way to start the app/attach the debugger. What WebStorm version do you use? here are 2 other ways to debug your app:

  • using Node.js run configuration (create similar configuration and press Debug):

enter image description here

  • using NPM run configuration:

    1. change your script to "debug": "node %NODE_DEBUG_OPTION% --require ts-node/register -r tsconfig-paths/register server.ts" (if you are on Linux/Mac OSX, replace %NODE_DEBUG_OPTION% with $NODE_DEBUG_OPTION

    2. click the arrow in the gutter, choose Debug

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.