
- Next.js - Home
- Next.js - Overview
- Next.js - Project Setup
- Next.js - Folder Structure
- Next.js - App Router
- Next.js - Page Router
- Next.js Features
- Next.js - Pages
- Next.js - Data Fetching
- Next.js - ISR
- Next.js - Static File Serving
- Next.js - Pre-Rendering
- Next.js - Partial Pre Rendering
- Next.js - Server Side Rendering
- Next.js - Client Side Rendering
- Next.js Routing
- Next.js - Routing
- Next.js - Nested Routing
- Next.js - Dynamic Routing
- Next.js - Parallel Routing
- Next.js - Imperative Routing
- Next.js - Shallow Routing
- Next.js - Intercepting Routes
- Next.js - Redirecting Routes
- Next.js - Navigation and Linking
- Next.js Configuration
- Next.js - TypeScript
- Next.js - Environment Variables
- Next.js - File Conventions
- Next.js - ESLint
- Next.js API & Backend
- Next.js - API Routes
- Next.js - Dynamic API Routes
- Next.js - Route Handlers
- Next.js - API MiddleWares
- Next.js - Response Helpers
- Next.js API Reference
- Next.js - CLI Commands
- Next.js - Functions
- Next.js - Directives
- Next.js - Components
- Next.js - Image Component
- Next.js - Font Component
- Next.js - Head Component
- Next.js - Form Component
- Next.js - Link Component
- Next.js - Script Component
- Next.js Styling & SEO
- Next.js - CSS Support
- Next.js - Global CSS Support
- Next.js - Meta Data
- Next.js Advanced Topics
- Next.js - Error Handling
- Next.js - Server Actions
- Next.js - Fast Refresh
- Next.js - Internationalization
- Next.js - Authentication
- Next.js - Session Management
- Next.js - Authorization
- Next.js - Caching
- Next.js - Data Caching
- Next.js - Router Caching
- Next.js - Full Route Caching
- Next.js - Request Memoization
- Next.js Performance Optimization
- Next.js - Optimizations
- Next.js - Image Optimization
- Next.js - Lazy Loading
- Next.js - Font Optimization
- Next.js - Video Optimization
- Next.js - Script Optimization
- Next.js - Memory Optimization
- Next.js - Using OpenTelemetry
- Next.js - Package Bundling Optimization
- Next.js Testing
- Next.js - Testing
- Next.js - Testing with Jest
- Next.js - Testing with Cypress
- Next.js - Testing with Vitest
- Next.js - Testing with Playwright
- Next.js Debugging & Deployment
- Next.js - Debugging
- Next.js - Deployment
- Next.js Useful Resources
- Next.js - Interview Questions
- Next.js - Quick Guide
- Next.js - Useful Resources
- Next.js - Discussion
Next.js - Debugging
Debugging is the process of identifying and fixing errors in the code. In Next.js, debugging can be done using browser developer tools or using Visual Studio Code. In this chapter, we will discuss how to debug Next.js applications using browser developer tools and Visual Studio Code.
Debugging with Browser DevTools
Most of the browsers provide developer tools section that can be used to debug and test web applications. Consider following code snippet for Next.js Home page. In the code, we defined a debugger statement when the count reaches greater than 5.
// /app/page.tsx "use client" import { useState } from "react"; export default function Home() { const [count, setCount] = useState(0); if (count > 5) { debugger; // Triggers when count exceeds 5 } return ( <div> <h2> Hello, Next.js! </h2> <p> Current Count: {count} </p> <button onClick={() => setCount(count + 1)}> Increment Count </button> </div> ); }
To debug this client side code, start your development server as usual by running next dev, npm run dev, or yarn dev. Once the server starts, open http://localhost:3000.
In the output, open developer tool of your browser.
- Open Developer Tools (Ctrl+Shift+J on Windows/Linux, Cmd+Shift+I on macOS)
- Go to the Sources tab ( Debugger tab in Firefox browser )
Any time the client-side code reaches debugger statement (ie, count greater than 6), the code execution will pause and that file will appear in the debug area. See the output below.

Debugging with VS Code
Vs code have inbuilt debugging tools for most of programming languages including Node.js. For activating debugging, open the debugging tab (near to extension tab) in VS code. In this tab you will see an option to "create a launch.json file", click on the link. This will create a ./.vscode/launch.json file, which can be used to customize debugging in VS code.
Now, consider the following code in Next.js home component, where we defined a for loop with breakpoint inside. The code will stop running at breakpoint, and we will print the value of variables in VS code console.
export default function Home() { var variable = 34; // Example of a loop where you can set breakpoints for (let i = 0; i < 10; i++) { // Define a breakpoint here to inspect the loop execution console.log(`Iteration: ${i}, Variable: ${variable}`); // Modify the variable to test variable changes during debugging variable += i; // Conditional statement to test conditional breakpoints if (i === 5) { console.log("Reached iteration 5"); } } return ( <div> <h2>Hello, Next.js!</h2> </div> ); }
When your code is ready, go to the Debug panel, select a launch configuration, then press F5 or select Debug: Start Debugging from the Command Palette to start your debugging session. In the VS code terminal, variable that are logged in console at the breakpoint in code. See the image of console below.
