Upgrading Next.js
Upgrading Next.js
Section titled “Upgrading Next.js”Introduction
Section titled “Introduction”Next.js releases major versions with new features, performance improvements, and breaking changes. Upgrading requires planning and testing.
Why Do We Need This?
Section titled “Why Do We Need This?”Each new version of Next.js includes performance improvements, new features, and security patches. Staying current gives you access to the latest capabilities.
Checking Your Version
Section titled “Checking Your Version”# Check installed versionnpx next --version
# Check what's availablenpm show next version # Latest stablenpm show next versions # All versionsUpgrade Steps
Section titled “Upgrade Steps”1. Read the Migration Guide
Section titled “1. Read the Migration Guide”# Every major release has an upgrade guide# https://nextjs.org/docs/app/building-your-application/upgrading2. Check for Deprecations
Section titled “2. Check for Deprecations”# Run the build to see deprecation warningsnpm run build
# Check for deprecated APIs in your code3. Update the Package
Section titled “3. Update the Package”# Install the latest versionnpm install next@latest
# Update related packages (react, react-dom)npm install react@latest react-dom@latest4. Resolve Breaking Changes
Section titled “4. Resolve Breaking Changes”Common breaking changes include:
- API changes (e.g.,
getServerSideProps→ Server Components) - Configuration changes (
next.config.jsoptions) - Dependency updates (Node.js version requirements)
- Image component changes
5. Test Thoroughly
Section titled “5. Test Thoroughly”# Build and check for errorsnpm run build
# Run testsnpm test
# Start production server and check manuallynpm startUpgrade Checklist
Section titled “Upgrade Checklist”- Read the official migration guide
- Check Node.js version requirements
- Update
nextand related packages - Resolve any TypeScript errors
- Run the full test suite
- Test in a preview deployment
- Monitor after production deployment
Common Mistakes
Section titled “Common Mistakes”- Skipping versions — Upgrade one major version at a time. Skipping versions (e.g., 12 → 14) makes migration much harder.
- Not checking the changelog — Each major version has specific breaking changes. Read the migration guide.
- Upgrading before testing — Always test the upgrade in a development or preview environment first.
Best Practices
Section titled “Best Practices”- Upgrade one major version at a time (e.g., 13 → 14, not 12 → 14)
- Read the official migration guide for each version
- Run the full test suite after upgrading
- Test in a preview deployment before production
- Update
reactandreact-domat the same time
Summary
Section titled “Summary”Upgrading Next.js requires planning. Read the migration guide, upgrade one major version at a time, and test thoroughly. Use preview deployments to verify before deploying to production.