Next.js Debug — Reference
Error Pattern Quick Lookup
| Log keyword / pattern | Class | Common cause | Next.js Docs |
|---|---|---|---|
Module not found: Can't resolve |
MODULE_ERROR |
Missing file, wrong path casing, uninstalled package | Resolving Modules |
Cannot find module '...' |
MODULE_ERROR |
Package not installed, tsconfig paths misconfigured | Path Aliases |
You're importing a component that needs |
BOUNDARY_ERROR |
Client component without "use client" |
Client Components |
Event handlers cannot be passed to Client Component |
BOUNDARY_ERROR |
Passing non-serializable props across Server/Client boundary | Passing Props to Client Components |
Hooks can only be called inside of the body of a function component |
BOUNDARY_ERROR |
Hook used in Server Component (no "use client") |
Client Components |
async/await is not yet supported in Client Components |
BOUNDARY_ERROR |
async keyword in a "use client" component |
Server Components |
Type error: TS2307 |
COMPILE_ERROR (→ MODULE_ERROR) |
Cannot find module or its type declaration | TypeScript |
SyntaxError: |
COMPILE_ERROR |
JS/TS syntax mistake | Error Handling |
Failed to compile |
COMPILE_ERROR |
Compilation failure; see nested error for detail | Error Handling |
Missing required environment variable |
ENV_ERROR |
Variable not set in .env* files |
Environment Variables |
process.env.* is undefined on client |
ENV_ERROR |
Variable lacks NEXT_PUBLIC_ prefix |
Environment Variables |
Invalid next.config.js options |
CONFIG_ERROR |
Unrecognized or removed config key | next.config.js Options |
Unrecognized key(s) in object |
CONFIG_ERROR |
Deprecated config option (e.g., target) |
Upgrade Guide |
Hydration failed |
RUNTIME_ERROR (hydration) |
Server/client render mismatch | Hydration Mismatch |
Text content did not match |
RUNTIME_ERROR (hydration) |
Dynamic content differs between SSR and client | Hydration Mismatch |
EADDRINUSE |
RUNTIME_ERROR (port) |
Port 3000 (or specified port) already in use | — |
getServerSideProps in app/ |
CONFIG_ERROR (version-specific) |
Pages Router API used in App Router | Data Fetching in App Router |
<Image layout= |
COMPILE_ERROR (version-specific) |
Removed next/image prop (Next.js < 13) |
Image Component |
Version Compatibility Matrix
| Next.js | Min Node.js | Recommended Node.js | React | Notes |
|---|---|---|---|---|
| 15.x | 18.18.0 | 20.x LTS | 19.x | Turbopack default in dev; React 19 required |
| 14.x | 18.17.0 | 20.x LTS | 18.x | App Router stable; use cache experimental |
| 13.x | 16.14.0 | 18.x LTS | 18.x | App Router introduced (beta → stable in 13.4) |
| 12.x | 12.22.0 | 16.x LTS | 17–18 | Pages Router only |
| ≤ 11.x | 10.13.0 | 14.x LTS | 16–17 | Pages Router only |
React/Next.js pairings to avoid:
next@15+react@18→ Peer dep warning; may cause hydration issues with Server Actionsnext@13/14+react@19→ Unsupported;useFormStateand related APIs differ
Deprecated & Removed APIs by Version
| API / Pattern | Removed/Changed in | Migration |
|---|---|---|
next/image layout, objectFit, objectPosition props |
Next.js 13 | Use fill + style={{ objectFit }} |
next/link <a> child required |
Next.js 13 | Wrap content directly in <Link> |
next.config.js target: 'serverless' |
Next.js 12 | Remove; use Vercel or custom server |
getServerSideProps / getStaticProps in app/ |
Next.js 13 | Use async Server Components + fetch() |
next/head in app/ |
Next.js 13 | Use generateMetadata() or metadata export |
next/router in app/ |
Next.js 13 | Use next/navigation (useRouter, usePathname) |
<Script strategy="worker"> requires nextScriptWorkers flag |
Next.js 13+ | Set experimental.nextScriptWorkers: true |
experimental.appDir |
Next.js 14 | Remove; App Router is stable by default |
Code Search Patterns by Error Class
MODULE_ERROR
# Find all import sites of a module
rg -n "from ['\"]<module-path>['\"]" app/ src/ lib/ components/ pages/
# Find a component file by name
find . -name "ComponentName.{tsx,ts,jsx,js}" -not -path "*/node_modules/*"
# or with glob
ls **/ComponentName.tsx 2>/dev/null
# Check tsconfig path aliases
rg -n "\"paths\"" tsconfig.json
# List all @/ imports to verify alias coverage
rg -n "from \"@/" app/ src/ --no-heading | head -20BOUNDARY_ERROR
# Find client components (should have "use client" on line 1)
rg -l "useState|useEffect|useRef|onClick|onChange" app/ --include="*.tsx"
# Find files with "use client"
rg -l "\"use client\"" app/
# Find Server Components using client-only APIs
rg -n "cookies\(\)|headers\(\)|cache\(\)" app/ --include="*.tsx"ENV_ERROR
# Find all process.env usages
rg -n "process\.env\." app/ src/ lib/ --include="*.{ts,tsx,js,jsx}"
# Find client-side env access without NEXT_PUBLIC_
rg -n "process\.env\." app/ --include="*.{ts,tsx}" | grep -v "NEXT_PUBLIC_"
# List all env files
ls -la .env* 2>/dev/nullCONFIG_ERROR
# Dump next.config content
cat next.config.js || cat next.config.ts || cat next.config.mjs
# Check for webpack callback in config (Turbopack won't run it)
rg -n "webpack:" next.config.*RUNTIME_ERROR (hydration)
# Find components using Date, Math.random, window in render
rg -n "new Date\(\)|Date\.now\(\)|Math\.random\(\)|window\." app/ --include="*.{ts,tsx}"
# Find useEffect-less window/document access
rg -n "typeof window|typeof document" app/ --include="*.{ts,tsx}"COMPILE_ERROR (TypeScript)
# Run type check without building
npx tsc --noEmit
# Check for TS errors in a specific file
npx tsc --noEmit --skipLibCheck src/app/page.tsx 2>&1 | head -20Common Fix Templates
Duplicate React — package.json overrides
// npm / pnpm
{
"overrides": {
"react": "^18.3.0",
"react-dom": "^18.3.0"
}
}
// yarn
{
"resolutions": {
"react": "^18.3.0",
"react-dom": "^18.3.0"
}
}tsconfig paths alias
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}Also requires in next.config.js (Next.js 12 only):
const nextConfig = {
experimental: { esmExternals: true }
}Next.js 13+ reads tsconfig.json paths automatically.
Port conflict
# macOS / Linux: kill process on port 3000
lsof -ti:3000 | xargs kill -9
# Or start on a different port
next dev -p 3001Clear stale .next cache
rm -rf .next && npm run dev # npm
rm -rf .next && pnpm dev # pnpm
rm -rf .next && yarn dev # yarn