Using Debugging Tools with Next.js – Full Stack Inspection with VS Code, DevTools, and Server Flags

Next.js supports full-stack debugging using tools like VS Code, Chrome DevTools, Firefox DevTools, and WebStorm. This article explains how to configure launch settings, inspect client and server code, use the --inspect flag, and debug across platforms with source maps and browser extensions.

Next.js debuggingVS CodeDevToolsNode inspect

~3 دقیقه مطالعه · آخرین به‌روزرسانی ۴ آبان ۱۴۰۴

Introduction


Next.js supports full-stack debugging with source maps, allowing you to inspect both frontend and backend code. You can use VS Code, Chrome DevTools, Firefox DevTools, or any debugger that attaches to Node.js.


Debugging with VS Code


Create a .vscode/launch.json file with the following configurations:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Next.js: debug server-side",
      "type": "node-terminal",
      "request": "launch",
      "command": "npm run dev"
    },
    {
      "name": "Next.js: debug client-side",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:3000"
    },
    {
      "name": "Next.js: debug client-side (Firefox)",
      "type": "firefox",
      "request": "launch",
      "url": "http://localhost:3000",
      "reAttach": true,
      "pathMappings": [
        {
          "url": "webpack://_N_E",
          "path": "${workspaceFolder}"
        }
      ]
    },
    {
      "name": "Next.js: debug full stack",
      "type": "node",
      "request": "launch",
      "program": "${workspaceFolder}/node_modules/next/dist/bin/next",
      "runtimeArgs": ["--inspect"],
      "skipFiles": ["/**"],
      "serverReadyAction": {
        "action": "debugWithEdge",
        "killOnServerStop": true,
        "pattern": "- Local:.+(https?://.+)",
        "uriFormat": "%s",
        "webRoot": "${workspaceFolder}"
      }
    }
  ]
}

Change debugWithEdge to debugWithChrome if using Chrome. Add cwd if your Next.js app is in a subdirectory (e.g. Turborepo).


Debugging with WebStorm


Create a JavaScript Debug configuration with http://localhost:3000 as the URL. Run it to open your browser and attach to both server and client code.


Client-Side Debugging with Browser DevTools


  • Start your server with npm run dev or next dev
  • Open http://localhost:3000 in Chrome or Firefox
  • Use Sources tab in Chrome or Debugger tab in Firefox
  • Press Ctrl+P / ⌘+P to search files and set breakpoints

Source paths will start with webpack://_N_E/./.


React Developer Tools


Install the React Developer Tools browser extension to inspect components, props, state, and performance issues.


Server-Side Debugging with --inspect


Use the --inspect flag to attach browser DevTools to your Node.js server:

NODE_OPTIONS='--inspect' next dev

For remote access (e.g. Docker):

NODE_OPTIONS='--inspect=0.0.0.0' next dev

Update package.json:

{
  "scripts": {
    "dev": "NODE_OPTIONS='--inspect' next dev"
  }
}

Attaching DevTools to Server


Chrome


  • Visit chrome://inspect
  • Click Configure and add localhost:9229
  • Find your app under Remote Target and click Inspect

Firefox


  • Visit about:debugging
  • Click This Firefox
  • Find your app under Remote Targets and click Inspect

Inspecting Server Errors


When an error occurs, Next.js shows a Node.js icon below the version indicator. Click it to copy the DevTools URL and inspect the server process.


Debugging on Windows


Windows doesn’t support NODE_OPTIONS='--inspect' syntax. Use cross-env:

{
  "scripts": {
    "dev": "cross-env NODE_OPTIONS='--inspect' next dev"
  }
}

Install with npm i -D cross-env. Disable Windows Defender to improve Fast Refresh performance.


Conclusion


Next.js offers robust debugging support across environments. Whether you're inspecting client-side code, server logic, or full-stack behavior, tools like VS Code, DevTools, and --inspect give you full visibility and control over your application.


نوشته و پژوهش‌شده توسط دکتر شاهین صیامی

مقالات مرتبط

Advanced Client-Side Routing and Performance Hooks in Next.js

Next.js provides a rich set of client-side hooks and caching utilities that empower developers to build dynamic, responsive, and secure applications. From reading route parameters to tracking navigation state and reporting performance metrics, this guide walks you through the most important tools available in the App Router.

ادامه

Handling Authorization and Caching in Next.js: A Developer’s Guide

Next.js introduces powerful experimental features for access control and smart caching. This guide covers the unauthorized() function for custom 401 handling, unstable_cache for persistent memoization, updateTag for instant cache invalidation, and useLinkStatus for inline navigation feedback. Learn how to use these tools to build secure, performant, and responsive applications.

ادامه

redirect and refresh in Next.js — Smart Redirects and Client Refreshing via Server Actions

The redirect function in Next.js allows you to navigate users to a new route, returning either a 307 or 303 HTTP response depending on context. It works in Server Components, Client Components, Route Handlers, and Server Actions. The refresh function is used exclusively within Server Actions to refresh the client router. This article explains how both functions work, with practical examples and key considerations.

ادامه

NextRequest and NextResponse in Next.js — Managing Cookies, Headers, Redirects, and Rewrites

Next.js extends the native Web Request and Response APIs with NextRequest and NextResponse, offering powerful tools for managing cookies, headers, redirects, rewrites, and JSON responses. These utilities simplify server-side logic and improve control over routing, personalization, and security. This guide walks through their capabilities with practical examples and best practices.

ادامه

headers, ImageResponse, notFound, and permanentRedirect in Next.js — Request Handling, Dynamic Images, Errors, and Redirects

Next.js offers powerful tools for handling HTTP requests and responses in Server Components. The headers function lets you read incoming request headers. ImageResponse allows you to generate dynamic images using JSX and CSS. The notFound function renders a custom 404 page, and permanentRedirect enables permanent redirection to another route. This article explains how to use each feature with practical examples.

ادامه

A Complete Guide to Using metadata and generateMetadata in Next.js

In modern versions of Next.js, managing page metadata is more powerful and intuitive than ever. Metadata is automatically injected into the <head> of your pages and plays a vital role in SEO, social sharing, and user experience. This guide explains the two main ways to define metadata: using the static metadata object and the dynamic generateMetadata function.

ادامه