Next.js Upgrade Protocol
Automated and manual migration steps for Next.js version upgrades (e.g., v14 to v15).
**Priority: P1 (HIGH)**
Workflow: Upgrade Next.js to New Major Version
- Check current versions of
next,react,react-dominpackage.json - Plan incremental path (e.g., v13 -> v14 -> v15; never skip majors)
- Run codemods:
npx @next/codemod@15.0.8 <transform> <path> - Update dependencies:
- Verify async APIs: ensure
cookies(),headers(),paramsawaited (v15+) - Audit
fetchcaching: v15 defaults tono-store; addforce-cachewhere needed - Run
next buildand fix hydration or Turbopack errors - Report codemod failures or manual fixes to team
Implementation Guidelines
- Upgrade Detection: Always check
package.jsonfor versions ofnext,react, andreact-dom. - Planning: For major version jumps (v13 to v15), perform incremental upgrade (v13 -> v14, then v14 -> v15). Follow official Next.js Migration Guides.
- Automated Codemods: Use
npx @next/codemod@15.0.8 <transform> <path>to automate syntax migration. - Codemod Version Pin: Every invocation is pinned to
@next/codemod@15.0.8for verified Next.js 15 migration transforms (such asnext-async-request-api); updating the pin requires fixture qualification of the retained commands. The pin covers this CLI only:upgradeoffers optional React 19 codemod prompts that execute floatingcodemod@latestandtypes-react-codemod@latestsubprocesses, so decline both and migrate React manually. Exact targets in the examples are fixture-qualified migration hops, not production or security recommendations; verify a real project's supported security fixes before choosing targets. - Breaking Changes (v15): Respond to
next-async-request-apitransform by ensuringparams,searchParams,cookies(), andheaders()awaited. - React Parity: Upgrade
reactandreact-domto match Next.js peer dependencies (e.g., React 19 for Next.js 15). - Validation: Run
next devandnext buildafter each incremental step. Check console errors for hydration warnings.
Anti-Patterns
- No major version skipping: Upgrade one major version at time (13 -> 14, then 14 -> 15).
- No manual breaking-change fixes: Always run
npx @next/codemod@15.0.8transforms first. - No floating codemod versions: Never run
@next/codemod@latest; execute the pinned@next/codemod@15.0.8release. - No assumed caching behavior post-upgrade: v15 defaults to
no-store; audit allfetchcalls. - No async page functions in Pages Router:
export default async function Page()fatal.