Debugging React Apps Written in TypeScript
Debugging is an essential part of any developer's workflow. However, debugging TypeScript in a React app requires some additional setup. This guide will show you how to set up your development environment to debug a React web app written in TypeScript.
VS Code
Set Up Debugging in VS Code
Open your project in VS Code.
Ensure that
package.jsoncontains a"start": "react-scripts start"script.Ensure that
tsconfig.jsonhas"sourceMap": truein thecompilerOptionsobject.Ensure the following configurations are set up in your launch.json file.
{ "default": "Start and Debug React App", // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Start React App", "type": "node-terminal", "request": "launch", "command": "npm start", "cwd": "${workspaceFolder}" }, { "name": "Debug React App", "type": "chrome", "request": "launch", "url": "http://localhost:3000", "webRoot": "${workspaceFolder}/src", "sourceMaps": true, "trace": true }, { "name": "Attach to Chrome", "type": "chrome", "request": "attach", "port": 9222, "webRoot": "${workspaceFolder}/src", "sourceMaps": true, "trace": true } ], "compounds": [ { "name": "Start and Debug React App", "configurations": ["Start React App", "Debug React App"] } ] }Press F5 to begin debugging.
JetBrains WebStorm
Set Up Debugging in WebStorm
Open your project in WebStorm.
Ensure that
package.jsoncontains a"start": "react-scripts start"script.Ensure that
tsconfig.jsonhas"sourceMap": truein thecompilerOptionsobject.Follow the instructions listed in the WebStorm documentation. Debug a TypeScript application running on an external web server.