This repository contains a Next.js application configured for easy debugging in Visual Studio Code. It includes client-side React pages, server-side API routes, a VS Code debug configuration, and notes about environment variables and tooling.
- .vscode/launch.json — VS Code debug configurations (server + client + attach).
- app/ — Next.js app route files and React components (client).
- app/api/... — API routes (server).
- docs/DEBUGGING.md — short troubleshooting & usage guide.
- dockerfile — optional development container (Debian-based).
- .env.local — example env file for local development.
- Node.js (recommended LTS, e.g., 18/20)
- npm (or yarn/pnpm)
- Visual Studio Code (with the "Debugger for Chrome"/built-in JS debugger)
- Install project deps:
cd e:/OnSpecDev/nextjs-debugging-app
npm install- Normal dev:
npm run dev
# or
next dev- Start server with Node inspector (for VS Code to attach):
npm run dev:debug
# (This runs Next.js with --inspect=9229 so VS Code can attach)Make sure package.json contains:
{
"scripts": {
"dev": "next dev",
"dev:debug": "node --inspect=9229 ./node_modules/next/dist/bin/next dev"
}
}A .vscode/launch.json is included with:
- "Next: Launch (dev)" — launches
npm run dev:debugand attaches the VS Code node debugger to the Next.js server. - "Next: Attach to server" — attach to an already-running process on port 9229.
- "Next: Client (Chrome)" and "Next: Client (Edge)" — launch a browser with remote debugging and map client source files via source maps.
- Compound "Next: Full (server + client)" — starts both server and client debug sessions together.
How to use:
- Open Run and Debug (Ctrl+Shift+D).
- Select "Next: Full (server + client)" and press Start (green arrow).
- Set breakpoints in server files (app/api/..., route.ts) or client .tsx files (e.g., app/fetch-test.tsx).
- Interact with the app in the launched browser. Breakpoints should pause execution.
Ensure source maps are enabled so breakpoints map to original TypeScript:
- tsconfig.json should include:
{
"compilerOptions": {
"sourceMap": true,
"inlineSources": true
}
}If breakpoints do not bind: confirm compiled files include source maps and that the debugger's webRoot matches the workspace root.
A sample .env.local is provided in the repo:
NEXT_PUBLIC_SENTRY_DSN=your_public_dsn
SENTRY_DSN=your_server_dsn
SENTRY_AUTH_TOKEN=your_sentry_auth_token
SENTRY_ORG=your_org
SENTRY_PROJECT=your_project
Notes:
- Variables starting with NEXT_PUBLIC_ are exposed to the browser. Do not put secrets there.
- SENTRY_DSN (no NEXT_PUBLIC_) is intended for server-side usage only.
- Replace placeholder values with real values for production/staging.
- Never commit secrets to version control. Add
.env.localto.gitignoreand store production secrets in your deployment provider (Vercel/Netlify/Azure/etc.) or a secrets manager.
- A development Dockerfile exists for Debian-based containers. It installs curl, bash, git, and attempts to install
cline. - The
clinenpm package may not support Windows host installs. If using the container, building and running it (Linux) avoids host platform restrictions. - Alternative on Windows: use WSL2 or install nvm-windows / nvm to manage Node versions.
- ESLint / config not picked up: ensure ESLint config file is at the workspace root and dependencies are installed.
- Breakpoints not hit:
- Server breakpoints: confirm you started Next.js with
--inspect=9229(usenpm run dev:debug) and either launch or attach with VS Code to port 9229. - Client breakpoints: use the Chrome/Edge debug configuration; ensure
webRootis correct and source maps are present.
- Server breakpoints: confirm you started Next.js with
- To inspect resolved ESLint config for a file:
npx eslint --print-config app/fetch-test.tsx- To debug ESLint resolution:
npx eslint "app/fetch-test.tsx" --ext .tsx --debug- npm install
- Open VS Code in the repo root
- Ensure tsconfig.json has sourceMap enabled
- Start "Next: Full (server + client)" in Run and Debug
- Set breakpoints in server or client files
- If server breakpoints not hit: start
npm run dev:debugthen "Attach to server" - For browser debugging, use the Chrome/Edge launch config that opens http://localhost:3000
- Keep secrets out of the repo. Use environment variables in production hosting.
- Validate that any client-exposed environment variables (NEXT_PUBLIC_*) do not reveal secrets.
- VS Code debugging docs: https://code.visualstudio.com/docs/editor/debugging
- Next.js debugging / source maps: Next.js docs and GitHub issues for mapping client/server stacks
- If something in this repo fails, open an issue including:
- Node version
- npm install output
- output of
npm run dev:debugor the VS Code Debug console