Skip to content
next-upgrade logo

Next.js Upgrade Workflow

next-upgrade

Structured workflow for upgrading Next.js applications across major versions. Use when migrating a Next.js project from one major version to another (e.g., 13 to 14, 14 to 15, 15 to 16). Covers codemod automation, breaking change detection, incremental migration paths, and post-upgrade validation.

oimiragieo/agent-studio0installs43stars

SKILL.md

Full skill instructions

Next.js Upgrade Workflow

Structured 9-step workflow for upgrading Next.js applications across major versions. Handles codemod automation, dependency updates, breaking change resolution, and validation.

When to Apply

Use this skill when:

  • Upgrading Next.js to a new major version (13, 14, 15, 16)
  • Running codemods to automate breaking change migrations
  • Resolving deprecation warnings in an existing Next.js project
  • Planning an incremental migration path for large codebases
  • Validating that an upgrade did not introduce regressions

9-Step Upgrade Workflow

Step 1: Detect Current Version

Identify the current Next.js version and target version.

# Check current version
cat package.json | grep '"next"'

# Check Node.js version (Next.js 15+ requires Node 18.18+, Next.js 16 requires Node 20+)
node --version

Version Requirements:

Next.jsMinimum Node.jsMinimum React
1316.1418.2.0
1418.1718.2.0
1518.1819.0.0
1620.019.0.0

Step 2: Create Upgrade Branch

git checkout -b upgrade/​nextjs-{target-version}

Always upgrade on a dedicated branch. Never upgrade on main directly.

Step 3: Run Codemods

Use the official Next.js codemod CLI to automate breaking change migrations.

# Interactive mode (recommended) -- selects applicable codemods
npx @next/​codemod@latest upgrade latest

# Or target a specific version
npx @next/​codemod@latest upgrade 15
npx @next/​codemod@latest upgrade 16

Key Codemods by Version:

Next.js 13 to 14
  • next-image-to-legacy-image -- Renames next/​image imports to next/​legacy/​image
  • next-image-experimental -- Migrates from next/​legacy/​image to new next/​image
  • metadata -- Moves Head metadata to Metadata API exports
Next.js 14 to 15
  • next-async-request-apis -- Converts synchronous dynamic APIs (cookies(), headers(), params, searchParams) to async
  • next-dynamic-ssr-false -- Replaces ssr: false with { loading } pattern for next/​dynamic
  • next-og-import -- Moves OG image generation imports to next/​og
Next.js 15 to 16
  • next-use-cache -- Converts unstable_cache to 'use cache' directive
  • next-cache-life -- Migrates cache revalidation to cacheLife() API
  • next-form -- Wraps <form> elements with next/​form where applicable

Step 4: Update Dependencies

# Update Next.js and React together
npm install next@latest react@latest react-dom@latest

# For Next.js 15+, also update React types
npm install -D @types/​react@latest @types/​react-dom@latest

# Update eslint config
npm install -D eslint-config-next@latest

Peer Dependency Conflicts:

If you encounter peer dependency conflicts:

  1. Check which packages require older React/​Next versions
  2. Update those packages first, or check for newer versions
  3. Use --legacy-peer-deps only as a last resort (document why)

Step 5: Update Configuration

Review and update next.config.js / next.config.ts:

// next.config.ts (Next.js 15+ recommends TypeScript config)
import type { NextConfig } from 'next';

const nextConfig: NextConfig = {
  // Next.js 15+: experimental features that graduated
  // Remove these from experimental:
  // - serverActions (now stable in 14+)
  // - appDir (now stable in 14+)
  // - ppr (now stable in 16+)

  // Next.js 16+: new cache configuration
  cacheComponents: true,  // Enable component-level caching
};

export default nextConfig;

Configuration Changes by Version:

VersionChange
14appDir removed from experimental (now default)
14serverActions removed from experimental (now stable)
15bundlePagesRouterDependencies now default true
15swcMinify removed (now always enabled)
16dynamicIO replaces several caching behaviors
16cacheComponents: true enables component caching

Step 6: Resolve Breaking Changes

After running codemods, manually resolve remaining breaking changes.

Common Breaking Changes (15 to 16):

  1. Async Request APIs: cookies(), headers(), params, searchParams are now async

    // Before (Next.js 14)
    export default function Page({ params }: { params: { id: string } }) {
      const { id } = params;
    }
    
    // After (Next.js 15+)
    export default async function Page({ params }: { params: Promise<{ id: string }> }) {
      const { id } = await params;
    }
    
  2. Caching Default Changed: fetch() requests are no longer cached by default in Next.js 15+

    // Before: cached by default
    fetch('https://api.example.com/​data');
    
    // After: explicitly opt-in to caching
    fetch('https://api.example.com/​data', { cache: 'force-cache' });
    // Or use 'use cache' directive in Next.js 16
    
  3. Route Handlers: GET route handlers are no longer cached by default

    // Next.js 15+: explicitly set caching
    export const dynamic = 'force-static';
    

Step 7: Run Tests

# Run existing test suite
npm test

# Run build to catch compile-time errors
npm run build

# Run dev server and check key pages manually
npm run dev

Validation Checklist:

  • Build completes without errors
  • All existing tests pass
  • Key user flows work in dev mode
  • No console warnings about deprecated APIs
  • Server-side rendering works correctly
  • Client-side navigation works correctly
  • API routes return expected responses
  • Middleware functions correctly
  • Static generation (SSG) pages build correctly

Step 8: Update TypeScript Types

# Regenerate TypeScript declarations
npm run build

# Fix any new type errors
npx tsc --noEmit

Common Type Fixes:

  • PageProps type changes (params/​searchParams become Promise in 15+)
  • Metadata type updates (new fields added)
  • NextRequest/NextResponse API changes
  • Route handler parameter types

Step 9: Document and Commit

# Create detailed commit
git add -A
git commit -m "chore: upgrade Next.js from {old} to {new}

Breaking changes resolved:
- [list specific changes]

Codemods applied:
- [list codemods run]

Manual fixes:
- [list manual changes]"

Incremental Upgrade Path

For large version jumps (e.g., 13 to 16), upgrade incrementally:

Next.js 13 -> 14 -> 15 -> 16

Why incremental?

  • Codemods are version-specific and may not compose correctly across multiple versions
  • Easier to debug issues when changes are smaller
  • Each version has its own set of breaking changes to resolve
  • Tests can validate each intermediate step

For each version step:

  1. Run codemods for that version
  2. Update deps
  3. Fix breaking changes
  4. Run tests
  5. Commit checkpoint
  6. Proceed to next version

Troubleshooting

Build fails after upgrade

  1. Clear .next directory: rm -rf .next
  2. Clear node_modules: rm -rf node_modules && npm install
  3. Clear Next.js cache: rm -rf .next/​cache

Module not found errors

  1. Check if package was renamed or merged
  2. Update imports per migration guide
  3. Check if package needs separate update

Hydration mismatches after upgrade

  1. Check for server/​client rendering differences
  2. Ensure dynamic imports use correct options
  3. Verify date/​locale handling is consistent

Middleware issues

  1. Middleware API changed in Next.js 13 (moved to root)
  2. NextResponse.rewrite() behavior changed in 15
  3. Check matcher configuration syntax

Iron Laws

  1. ALWAYS upgrade on a dedicated branch, never on main directly — upgrade branches can be rebased or reverted without disrupting production; direct main upgrades risk deploying half-migrated code.
  2. NEVER skip intermediate versions in a multi-version jump — Next.js codemods are version-specific and do not compose correctly across major versions; skipping steps leaves un-migrated breaking changes.
  3. ALWAYS run official codemods before making manual changes — codemods handle the bulk of mechanical migrations; manual-first approaches miss patterns and create divergence from the reference migration path.
  4. NEVER use --legacy-peer-deps without documenting the specific conflict and resolution plan — suppressing peer errors hides version conflicts that will cause runtime failures.
  5. ALWAYS validate with a full build plus test suite before merging — the dev server does not exercise SSG, edge runtime, or build optimizations that can fail silently post-upgrade.

Anti-Patterns

Anti-PatternWhy It FailsCorrect Approach
Upgrading on the main branch directlyHalf-migrated code can reach production; rollback requires a revert commitAlways create upgrade/​nextjs-{version} branch; merge only after full validation
Skipping intermediate versionsVersion-specific codemods are not composable; skipped breaking changes cause runtime failuresUpgrade one major version at a time: 13→14→15→16; commit a checkpoint at each step
Manual migration before running codemodsCreates divergence from codemod output; codemods cannot merge cleanly with manual editsRun codemods first; apply manual fixes only for patterns codemods could not handle
Using --legacy-peer-deps without documentationHidden version conflicts cause runtime failures not visible at install timeResolve conflicts explicitly; use the flag only with a documented justification
Validating only in dev modeDev server skips SSG, edge runtime, and build optimizations that can fail post-upgradeRun npm run build plus the full test suite; check SSR, SSG, and API routes explicitly

References

More skills from oimiragieo

cloud-devops-expert logo
oimiragieo/agent-studio

cloud-devops-expert

Cloud and DevOps expert including AWS, GCP, Azure, and Terraform

43 0
View
xlsx logo
oimiragieo/agent-studio

xlsx

Spreadsheet toolkit (.xlsx/.csv). Create/edit with formulas/formatting, analyze data, visualization, recalculate formulas, for spreadsheet processing and analysis.

43 0
View
project-analyzer logo
oimiragieo/agent-studio

project-analyzer

Automated brownfield codebase analysis with weighted keyword scoring, three-stream analysis, and design pattern recognition. Detects project type, frameworks, dependencies, architecture patterns, and generates comprehensive project profile.

43 0
View
readme logo
oimiragieo/agent-studio

readme

Use when creating, updating, or generating README and documentation files for projects and libraries

43 0
View
scientific-writing logo
oimiragieo/agent-studio

scientific-writing

Core skill for the deep research and writing tool. Write scientific manuscripts in full paragraphs (never bullet points). Use two-stage process with (1) section outlines with key points using research-lookup then (2) convert to flowing prose. IMRAD structure, citations (APA/AMA/Vancouver), figure...

43 0
View
android-expert logo
oimiragieo/agent-studio

android-expert

Comprehensive Android development expert covering Jetpack Compose, Kotlin coroutines/Flow, Architecture Components, Hilt DI, Navigation, testing, performance, Material Design 3, and modern Android patterns (MVI, Clean Architecture).

43 0
View
biorxiv-database logo
oimiragieo/agent-studio

biorxiv-database

Efficient database search tool for bioRxiv preprint server. Use this skill when searching for life sciences preprints by keywords, authors, date ranges, or categories, retrieving paper metadata, downloading PDFs, or conducting literature reviews.

43 0
View
omega-gemini-cli logo
oimiragieo/agent-studio

omega-gemini-cli

Use when the user wants to use Google Gemini for analysis, large files or codebases, sandbox execution, or brainstorming. Uses headless Gemini CLI scripts (no MCP). Triggers on "use Gemini", "analyze with Gemini", "large file", "sandbox", "brainstorm with Gemini".

43 0
View
gtars logo
oimiragieo/agent-studio

gtars

High-performance toolkit for genomic interval analysis in Rust with Python bindings. Use when working with genomic regions, BED files, coverage tracks, overlap detection, tokenization for ML models, or fragment analysis in computational genomics and machine learning applications.

43 0
View
service-class-conventions logo
oimiragieo/agent-studio

service-class-conventions

Defines the structure and implementation of service classes, enforcing the use of interfaces, ServiceImpl classes, DTOs for data transfer, and transactional management.

43 0
View
diffdock logo
oimiragieo/agent-studio

diffdock

Diffusion-based molecular docking. Predict protein-ligand binding poses from PDB/SMILES, confidence scores, virtual screening, for structure-based drug design. Not for affinity prediction.

43 0
View
skill-discovery logo
oimiragieo/agent-studio

skill-discovery

How agents discover and use skills. Use to understand skill invocation protocol.

43 0
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View