Next.js Upgrade Protocol
Automated and manual migration steps for Next.js version upgrades (e.g., v14 to v15).
Priority: P1 (OPERATIONAL)
Workflow: Upgrade Next.js to a 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@latest <transform> <path> - Update dependencies: See implementation examples
- Verify async APIs: ensure
cookies(),headers(),paramsare awaited (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 the team
Implementation Guidelines
- Upgrade Detection: Always check
package.jsonfor versions ofnext,react, andreact-dom. - Planning: For major version jumps (v13 to v15), perform an incremental upgrade (v13 -> v14, then v14 -> v15). Follow the official Next.js Migration Guides.
- Automated Codemods: Use
npx @next/codemod@latest <transform> <path>to automate syntax migration. - Breaking Changes (v15): Respond to the
next-async-request-apitransform by ensuringparams,searchParams,cookies(), andheaders()are 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 a time (13 -> 14, then 14 -> 15).
- No manual breaking-change fixes: Always run
npx @next/codemod@latesttransforms first. - 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()is fatal.