How to debug my Node.js TypeScript project in Chrome dev tools

696 Views Asked by At

I am trying to add a debug script in my package.json file. For a plain Node project this code works:

"debug": "node --inspect index.js"

And for Node TypeScript project I did this:

"debug": "ts-node --inspect --require ts-node/register index.ts"

But this gives me error:

Error: Unknown or unexpected option: --inspect

What should I do?

1

There are 1 best solutions below

0
Brian On

Use the following command to pass the --inspect option directly to node as indicated in this ts-node issue.

node <node options here> --require ts-node/register

or

node <node options here> --loader ts-node/esm

So for your example, it would be

 "debug": "node --inspect --require ts-node/register index.ts"