Upgrading a Next.js static export without surprises

How to upgrade Next.js and React in a static-export app, prune dead files and unused packages safely, and verify a critical journey before launch.

Upgrading a Next.js and React codebase that deploys as a static export is easiest when you separate framework upgrades, dead-code cleanup, and feature work into reviewable stages instead of mixing them into one giant branch.

During my upgrade work on Curvance’s lending app, moving the site to Next.js 16 and its newer router while keeping it a static export also surfaced 493 dead files and 30 unused packages. Having a clear sequence keeps cleanup like that safe instead of stressful.

1. Establish the static-export baseline first

Before bumping versions, record what a clean build currently produces:

  • Pin the exact Node or package-manager version in the repository and verify a fresh install and static build succeed without manual tweaks.
  • Inventory every route generated in the output directory, including trailing-slash behavior, redirects, and custom 404 handling.
  • Identify one critical user journey to protect end to end—such as loading live data, switching tabs, or completing a primary client interaction—and verify how you will test it after each step.

2. Check static-export constraints early

Static exports (output: 'export') reject runtime server features that silently sneak in during upgrades:

  • Audit dynamic route segments to ensure every valid parameter is enumerated at build time (generateStaticParams or equivalent).
  • Verify image handling (images: { unoptimized: true } or a custom static loader) and confirm headers or redirects are enforced by your host configuration rather than Next.js middleware.
  • Separate browser-only dependencies (window, localStorage, wallet or chart SDKs) cleanly behind client boundaries so static pre-rendering never crashes on server-side globals.

3. Prune unused code and dependencies deliberately

Old repositories often accumulate unused pages, components, hooks, and npm packages that block React or TypeScript upgrades for no reason.

  1. Run static reachability checks across entry points, routes, tests, and config files to find unreferenced modules and packages.
  2. Review every candidate before deletion—dynamic imports, build scripts, and CSS entry points can hide legitimate references.
  3. Remove unused dependencies in dedicated commits so typecheck, build, and runtime diffs stay small and reversible.

4. Upgrade in bounded steps and verify on a preview host

Apply the React, TypeScript, and Next.js upgrades only after the baseline is clean:

  • Address deprecation warnings and router changes systematically rather than suppressing type errors.
  • Diff the generated output directory against your baseline to catch missing routes, broken canonical paths, or unexpected asset growth.
  • Deploy the static output to a preview URL and run your agreed critical-journey checks, console-error checks, and rollback rehearsal before promoting to production.

Need help applying this to your codebase?

Start with a free 20-minute call. We can discuss your repository, confirm scope and pricing in writing, or choose a short review first.

Request a free 20-minute call