Agent Skillsaresbit/MateBot › nextjs-server-side-error-debugging

nextjs-server-side-error-debugging

GitHub

解决 Next.js 服务端渲染(getServerSideProps/getStaticProps)及 API 路由报错时浏览器无详细堆栈的问题,指导检查终端日志、添加错误处理及排查生产环境原因。

skills/claudeception/examples/nextjs-server-side-error-debugging/SKILL.md aresbit/MateBot

Trigger Scenarios

页面显示内部服务器错误但浏览器控制台为空 API 路由返回 500 且无详细信息 服务端代码静默失败 仅在刷新或直连导航时出现错误

Install

npx skills add aresbit/MateBot --skill nextjs-server-side-error-debugging -g -y
More Options

Non-standard path

npx skills add https://github.com/aresbit/MateBot/tree/master/skills/claudeception/examples/nextjs-server-side-error-debugging -g -y

Use without installing

npx skills use aresbit/MateBot@nextjs-server-side-error-debugging

指定 Agent (Claude Code)

npx skills add aresbit/MateBot --skill nextjs-server-side-error-debugging -a claude-code -g -y

安装 repo 全部 skill

npx skills add aresbit/MateBot --all -g -y

预览 repo 内 skill

npx skills add aresbit/MateBot --list

SKILL.md

Frontmatter
{
    "date": 1705276800,
    "name": "nextjs-server-side-error-debugging",
    "author": "Claude Code",
    "version": "1.0.0",
    "description": "Debug getServerSideProps and getStaticProps errors in Next.js. Use when: \n(1) Page shows generic error but browser console is empty, (2) API routes \nreturn 500 with no details, (3) Server-side code fails silently, (4) Error \nonly occurs on refresh not client navigation. Check terminal\/server logs \ninstead of browser for actual error messages.\n"
}

Next.js Server-Side Error Debugging

Problem

Server-side errors in Next.js don't appear in the browser console, making debugging frustrating when you're looking in the wrong place. The browser shows a generic error page or 500 status, but no stack trace or useful error information appears in DevTools.

Context / Trigger Conditions

This skill applies when:

  • Page displays "Internal Server Error" or custom error page
  • Browser console shows no errors, or only a generic fetch failure
  • You're using getServerSideProps, getStaticProps, or API routes
  • Error only occurs on page refresh or direct navigation (not client-side transitions)
  • The error is intermittent and hard to reproduce in the browser

Common misleading symptoms:

  • "Unhandled Runtime Error" modal that doesn't show the real cause
  • Network tab shows 500 but response body is empty or generic
  • Error disappears when you add console.log (timing issue)

Solution

Step 1: Check the Terminal

The actual error with full stack trace appears in the terminal where npm run dev or next dev is running. This is the first place to look.

# If you don't see the terminal, find the process
ps aux | grep next
# Or restart with visible output
npm run dev

Step 2: Add Explicit Error Handling

For persistent debugging, wrap server-side code with try-catch:

export async function getServerSideProps(context) {
  try {
    const data = await fetchSomething();
    return { props: { data } };
  } catch (error) {
    console.error('getServerSideProps error:', error);
    // Return error state instead of throwing
    return { props: { error: error.message } };
  }
}

Step 3: For Production Errors

Check your hosting provider's logs:

  • Vercel: Dashboard → Project → Logs (Functions tab)
  • AWS: CloudWatch Logs
  • Netlify: Functions tab in dashboard
  • Self-hosted: Check your Node.js process logs

Step 4: Common Causes

  1. Environment variables: Missing in production but present locally
  2. Database connections: Connection string issues, cold starts
  3. Import errors: Server-only code accidentally imported on client
  4. Async/await: Missing await on async operations
  5. JSON serialization: Objects that can't be serialized (dates, functions)

Verification

After checking the terminal, you should see:

  • Full stack trace with file name and line number
  • The actual error message (not generic 500)
  • Variable values if you added console.log statements

Example

Symptom: User reports page shows "Internal Server Error" after clicking a link.

Investigation:

  1. Open browser DevTools → Console: Empty
  2. Network tab shows: GET /dashboard → 500
  3. Check terminal running npm run dev:
Error: Cannot read property 'id' of undefined
    at getServerSideProps (/app/pages/dashboard.tsx:15:25)
    at renderToHTML (/app/node_modules/next/dist/server/render.js:428:22)

Cause found: Database query returned null instead of user object.

Notes

  • In development, Next.js sometimes shows an error overlay, but it often has less detail than the terminal output
  • reactStrictMode: true in next.config.js causes double-execution of server functions in development, which can make debugging confusing
  • For API routes, the error appears in the same terminal as page errors
  • Client-side errors (in useEffect, event handlers) DO appear in browser console— this skill only applies to server-side code
  • If using next start (production mode locally), errors may be less verbose; check NODE_ENV and consider adding custom error logging

Version History

  • 2328a17 Current 2026-08-20 10:30

Same Skill Collection

matecode/SKILL.md
skills/3d-cad-skill/SKILL.md
skills/agent-browser/SKILL.md
skills/arkts-agent-skill/SKILL.md
skills/autoresearch-skill/SKILL.md
skills/baoyu-post-to-wechat/SKILL.md
skills/blogwatcher/SKILL.md
skills/c-skill/SKILL.md
skills/chrome-cdp/SKILL.md
skills/claudeception/.claude/skills/continuous-learning/SKILL.md
skills/claudeception/examples/prisma-connection-pool-exhaustion/SKILL.md
skills/claudeception/examples/typescript-circular-dependency/SKILL.md
skills/claudeception/SKILL.md
skills/clawdhub/SKILL.md
skills/coding-agent/SKILL.md
skills/docx/SKILL.md
skills/ebook/book-architect/SKILL.md
skills/ebook/book-idea-validator/SKILL.md
skills/ebook/book-ideation/SKILL.md
skills/ebook/book-market-research/SKILL.md
skills/ebook/chapter-architect/SKILL.md
skills/elf-patcher/SKILL.md
skills/excalidraw-diagram-skill/SKILL.md
skills/frontend-slides/SKILL.md
skills/gemini/SKILL.md
skills/gifgrep/SKILL.md
skills/git-wt/SKILL.md
skills/github/SKILL.md
skills/harmonyos-code-review/SKILL.md
skills/harmonyos-linux-cli-dev/SKILL.md
skills/harmonyos-skills/skills/harmonyos-game-generator/SKILL.md
skills/harmonyos-skills/skills/harmonyos-test-cases/SKILL.md
skills/harmonyos-skills/skills/harmonyos-ui-automator/SKILL.md
skills/harmonyos-skills/skills/ohos-app-build-debug/SKILL.md
skills/hm-fetch-skill/SKILL.md
skills/hm-framework-skill/SKILL.md
skills/humanizer/SKILL.md
skills/ian-gemini-web/SKILL.md
skills/kernel-dev-skill/SKILL.md
skills/kimi/docx_SKILL.md
skills/kimi/pdf_SKILL.md
skills/kimi/SKILL.md
skills/kimi/webapp-building_SKILL.md
skills/lecture-skill/SKILL.md
skills/macos-menubar-tuist-app/SKILL.md
skills/macos2linuxapp/SKILL.md
skills/matecode/SKILL.md
skills/medialibrary-ut-generator/SKILL.md
skills/mermaid-validator/SKILL.md

Metadata

Files
0
Version
2328a17
Hash
3e317bc7
Indexed
2026-08-20 10:30

- 위키
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-25 15:14
浙ICP备14020137号-1 $방문자$