Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one debug NextJS React apps with WebStorm?

I'm trying to use the WebStorm IDE debugger to debug a NextJS React app. I tried to use a JavaScript configuration, but that didn't seem to work -- neither when I used a Node config.

What's the correct procedure for debugging NextJS React apps with WebStorm?

like image 749
Cerulean Avatar asked Jan 24 '19 19:01

Cerulean


People also ask

How do you debug Nextjs applications?

Now go to the Debug panel ( Ctrl + Shift + D on Windows/Linux, ⇧ + ⌘ + D on macOS), select a launch configuration, then press F5 or select Debug: Start Debugging from the Command Palette to start your debugging session.

How do I run the react app in debug mode?

There are two main ways in which we can use them: By writing the debugger statement in our source code. By clicking on a specific line of the code in the Chrome web browser (or Firefox, Edge, etc.) Developer Tools.


2 Answers

The following steps work for me:

  • start the app with next (npm run dev or whatever your start script looks like)
  • add breakpoints, create JavaScript Debug run configuration, specify http://localhost:3000 URL
  • debug

If you like to debug the code that is executed on the server side, I'd suggest using the Node.js run configuration with node_modules\next\dist\bin\next specified as Javascript file:

enter image description here

You can then debug both Node.js and Javascript Debug run configurations to get both server-side and client-side code debugged.

like image 141
lena Avatar answered Sep 22 '22 22:09

lena


I found that clicking the play button next to dev in package.json and selecting the debug option worked for debugging my API served by Next.js.

enter image description here

This automatically creates the run configuration. Breakpoints are flakey though, I think because I'm using TypeScript. I need to edit the file after adding the breakpoint for them to work.

like image 39
David Gilbertson Avatar answered Sep 18 '22 22:09

David Gilbertson