{
  "id": "migrate-nextjs-14-to-16",
  "type": "playbooks",
  "category": "playbooks",
  "locale": "fr",
  "url": "/fr/playbooks/migrate-nextjs-14-to-16",
  "title": "Prompt-to-PR: Migrer Next.js 14 vers 16",
  "description": "Procédure pas à pas (SOP) pour migrer un projet Next.js 14 avec App Router vers Next.js 16 — Turbopack, React 19, les API asynchrones et les modifications de mise en cache sont couverts.",
  "tools": [
    "Cursor",
    "Claude Code",
    "Codex",
    "Windsurf"
  ],
  "stack": [
    "Next.js",
    "TypeScript"
  ],
  "tags": [
    "nextjs",
    "typescript",
    "migrate"
  ],
  "difficulty": "hard",
  "updated": "2026-06-08",
  "markdown": "Next.js 16 embarque React 19, les `params` et `searchParams` asynchrones, une refonte complète du cache des requêtes `fetch`, et Turbopack comme bundler de développement par défaut. Ce guide permet à l'agent de se concentrer sur les changements cassants et l'empêche de réécrire du code fonctionnel.\n\n## 1. Prérequis\n\nMettre à jour `next` de 14.x à 16.x (et `react`/`react-dom` vers 19.x) sans aucune régression fonctionnelle. Traiter chaque changement cassant révélé par le codemod officiel ainsi que tout problème résiduel qu'il n'a pas détecté.\n\n## 2. Premier Prompt\n\n```txt title=\"First Prompt\"\nMigrate this project from Next.js 14 to Next.js 16. Follow these steps exactly.\n\nStep 1 — run the official codemod:\n  npx @next/codemod@latest upgrade latest --yes\n\nStep 2 — manual fixes the codemod does not cover:\n  a. `params` and `searchParams` in page.tsx/layout.tsx files are now Promises.\n     Await them: `const { id } = await params;`\n     Do NOT destructure params in the function signature.\n  b. `cookies()`, `headers()`, `draftMode()` are now async.\n     Add `await` before every call.\n  c. `fetch()` is no longer cached by default in Route Handlers.\n     Where caching is intentional, add `{ next: { revalidate: N } }`.\n  d. Remove any `export const dynamic = 'force-dynamic'` that is now the default.\n  e. Replace `<Image>` with the new `onLoad` prop signature if present.\n\nStep 3 — update package.json:\n  \"next\": \"^16.0.0\"\n  \"react\": \"^19.0.0\"\n  \"react-dom\": \"^19.0.0\"\n  \"@types/react\": \"^19.0.0\"\n  \"@types/react-dom\": \"^19.0.0\"\n\nDo not change any business logic, UI, or database code.\nList every file you changed and why.\n```\n\n## 3. Modifications de fichiers attendues\n\n```txt\npackage.json                          (next, react, react-dom, @types/react*)\nsrc/app/**/page.tsx                   (await params / searchParams)\nsrc/app/**/layout.tsx                 (await params where used)\nsrc/app/api/**/route.ts               (await cookies/headers; fetch cache opts)\nsrc/middleware.ts                     (if it uses deprecated config keys)\nnext.config.ts                        (remove deprecated options)\n```\n\n## 4. Liste de vérification\n\n- `package.json` fixe `next` à `^16.0.0` et React à `^19.0.0`.\n- Chaque page/layout qui déstructure `params` doit d'abord l'attendre avec `await`.\n- Aucun appel synchrone à `cookies()` ou `headers()` ne subsiste dans les composants serveur.\n- Les appels `fetch` qui reposaient auparavant sur une mise en cache implicite doivent avoir une option `revalidate` ou `no-store` explicite.\n- `next.config.ts` ne contient pas les clés obsolètes `experimental.appDir` ou `swcMinify`.\n- TypeScript compile avec `bun tsc --noEmit` — zéro erreur.\n- L'agent n'a réécrit aucun composant d'interface ni logique métier.\n\n## 5. Commandes de test\n\n```bash\n# Install updated deps\nbun install\n\n# Type-check\nbun tsc --noEmit\n\n# Dev build (Turbopack default in Next.js 16)\nbun dev\n\n# Production build — catches async-params errors at compile time\nbun run build\n\n# Run existing test suite\nbun test\n```\n\n## 6. Échecs courants\n\n- **`params.id` utilisé avant await** — Erreur TypeScript : `Property 'id' does not exist on type 'Promise<...>'`. L'agent attend parfois `params` dans un fichier mais pas dans un autre.\n- **`cookies()` non attendu** — Erreur d'exécution : `cookies() was called outside of a Server Component`. Ajoutez `await`.\n- **Plugin webpack incompatible avec Turbopack** — `next dev` génère une erreur sur une configuration `webpack()` personnalisée. Turbopack ignore les plugins webpack ; migrez-les ou conditionnez-les.\n- **Conflit de version `@types/react`** — Incompatibilité de dépendance peer entre les anciennes bibliothèques de composants et les types React 19. Épinglez `@types/react` à la version 19 et remplacez si nécessaire.\n- **`useFormState` supprimé** — remplacé par `useActionState` de `react`. Le codemod détecte généralement cela, mais vérifiez.\n\n## 7. Prompt de correction\n\n```txt title=\"Fix Prompt\"\nTypeScript reports: \"Property 'slug' does not exist on type\n'Promise<{ slug: string }>'\" in src/app/blog/[slug]/page.tsx.\n\nThe page function signature must be:\n  export default async function Page({ params }: { params: Promise<{ slug: string }> })\n\nThen at the top of the function body:\n  const { slug } = await params;\n\nApply the same fix to every other page or layout that destructures params\nwithout awaiting. List every file changed.\n```\n\n## 8. Description de la PR\n\n```md title=\"PR description\"\n## Chore: Migrate Next.js 14 → 16 + React 19\n\n**Breaking changes addressed**:\n- `params` / `searchParams` are now `Promise`s — awaited in all pages/layouts\n- `cookies()` / `headers()` are now async — awaited in all Server Components\n- Fetch caching defaults changed — explicit `revalidate` added where needed\n- Removed deprecated `next.config.ts` keys (`swcMinify`, `experimental.appDir`)\n\n**Tooling**: dev server now uses Turbopack by default (`next dev --turbopack`).\n\nRun `bun run build` to confirm zero type errors before merging.\n```"
}