Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug TypeScript in WebStorm Node.js Remote Debug?

Tags:

I have a TypeScript Node.js Restify app running inside Docker container. I can connect the WebStorm Node.js Remote Debugger, but I can only debug the compiled JS files and not the TS files.

In the tsconfig.json I have "sourceMap": true set.

Is there anything I am missing?

like image 841
Nelson Avatar asked Aug 28 '17 15:08

Nelson


People also ask

How do I run a TypeScript code in WebStorm?

WebStorm configuration In Languages & Frameworks select TypeScript, Select the option Enable TypeScript Compiler, In Command Line Options: type –module commonjs, And set the value dev (or js or whatever you like) for the Use output path: so we don't mix TypeScript and JavaScript files.

Does WebStorm work with TypeScript?

With WebStorm, you can run and debug client-side TypeScript code and TypeScript code running in Node. js. Learn more from Running and debugging TypeScript.

How do I debug angular projects in WebStorm?

Hold Ctrl+Shift and click this URL link. WebStorm starts a debugging session with an automatically generated Angular Application configuration of the type JavaScript Debug.


1 Answers

I have found a solution using ts-node there are a few steps that you should do for doing it.

First, you must add "esModuleInterop": true and "sourceMap": true to your tsconfig.json

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "target": "es6",
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "dist"
  },
  "lib": ["es2015"]
}

After that, you should install the ts-node package.

npm i -D ts-node

The last step is adding to edit the Run/Debug Configurations of the WebStorm.

Go to Run/Debug Configurations window.

Add new Node.js configuration using the +.

Change the Node parameters to --require ts-node/register

Then, change the Javascript file to your Typescript file, for me it is: src/app.ts

Press the OK button.

Run this configuration as dubug.

like image 196
Itay Cohen Avatar answered Oct 11 '22 12:10

Itay Cohen