Debugging TypeScript

Most often, you may want to debug a client-side application running on an external development web server, e.g. powered by Node.js. If your application is running on the built-in PhpStorm server, you can also debug it in the same way as JavaScript running on the built-in server.

With PhpStorm, you set breakpoints in the original TypeScript code instead of the compiled JavaScript that is actually executed. PhpStorm recognizes and processes breakpoints in TypeScript using source maps.

To generate source maps during compilation

Open the tsconfig.json file and make sure the sourceMap property is set to true.

To debug a TypeScript application running on an external web server

Compile the TypeScript code into JavaScript, see Compiling TypeScript. Make sure source maps are generated.

Run the application in the development mode. Often you need to run npm start for that. When the development server is ready, copy the URL address at which the application is running in the browser - you will need to specify this URL address in the run/debug configuration.

Choose Run | Edit Configuration from the main menu, click on the toolbar and select JavaScript Debug from the list. In the Run/Debug Configuration: JavaScript Debug dialog that opens, specify the URL address at which the application is running. This URL can be copied from the address bar of your browser as described in Step 3 above.

Choose the newly created configuration in the Select run/debug configuration drop-down list on the toolbar and click . The URL address specified in the run configuration opens in the chosen browser and the Debug Tool Window appears.