{
  "id": "migrate-nextjs-14-to-16",
  "type": "prompts",
  "category": "prompts",
  "locale": "fr",
  "url": "/fr/prompts/migrate-nextjs-14-to-16",
  "title": "Invite pour migrer une application Next.js 14 vers Next.js 16",
  "description": "Invite structurée pour agent IA afin de migrer un projet Next.js 14 App Router vers Next.js 16 avec gestion des changements cassants et étapes incrémentales.",
  "tools": [
    "Cursor",
    "Claude Code",
    "Codex",
    "Windsurf"
  ],
  "stack": [
    "Next.js",
    "TypeScript"
  ],
  "tags": [
    "nextjs",
    "typescript",
    "migrate"
  ],
  "difficulty": "hard",
  "updated": "2026-06-08",
  "markdown": "Utilisez cette invite pour mener une migration prudente et incrémentale de Next.js 14 vers 16 — en gérant\nle changement d'API asynchrone `params`/`searchParams`, la dépendance de paire React 19, et les motifs\nobsolètes de `next/headers` avant la mise à niveau.\n\n## Invite principale\n\n```txt title=\"Main Prompt\"\nYou are migrating an existing Next.js 14 App Router project to Next.js 16.\n\nDo this in the following ordered steps — do not skip steps or combine them.\n\nStep 1 — Audit (read-only):\n  - List every file that uses `params` or `searchParams` as synchronous props.\n  - List every file that calls `cookies()`, `headers()`, or `draftMode()` without `await`.\n  - List every `next/image` usage with a deprecated prop (e.g., `layout`, `objectFit`).\n  - List the current `peerDependencies` for React and React DOM.\n  Output the audit as a plain list. Stop and wait for my review.\n\nStep 2 — Update deps:\n  - Run: `bun add next@16 react@19 react-dom@19 @types/react@19 @types/react-dom@19`\n  - Do NOT change any source files in this step.\n\nStep 3 — Fix async params:\n  - For every Page, Layout, and `generateMetadata` function that receives `params` or\n    `searchParams`, make the function `async` and `await` the prop before use.\n  - Type the props as `Promise<{ slug: string }>` (or the relevant shape), not `{ slug: string }`.\n\nStep 4 — Fix async dynamic APIs:\n  - Add `await` before every call to `cookies()`, `headers()`, and `draftMode()`.\n  - If the call is inside a non-async function, make that function async.\n\nStep 5 — Fix deprecated Image props:\n  - Remove `layout=\"fill\"` and replace with `fill` (boolean).\n  - Remove `objectFit` and `objectPosition` props and move them to a `className` or `style`.\n\nStep 6 — Verify:\n  - Run `bun run typecheck` and fix all remaining TypeScript errors.\n  - Run `bun run build` and confirm exit 0.\n\nAfter each step, show the diff and wait for confirmation before proceeding.\n```\n\n## Notes d'implémentation\n\n- Dans Next.js 15+, `params` et `searchParams` sont enveloppés dans une `Promise`. Y accéder de manière synchrone\n  compilera mais générera une erreur à l'exécution — l'audit à l'étape 1 est essentiel avant la mise à niveau.\n- `cookies()` et `headers()` sont asynchrones dans Next.js 15+ ; le mode d'échec le plus courant est de les appeler\n  à l'intérieur d'une fonction qui n'est pas marquée `async`.\n- React 19 supprime certaines API héritées (`defaultProps` sur les composants fonction, les refs sous forme de chaîne). Exécutez\n  `bun run typecheck` entre chaque étape pour les détecter tôt.\n\n## Modifications de fichiers attendues\n\n```txt\npackage.json                          (edited — next, react, react-dom versions)\nbun.lock / package-lock.json          (edited automatically)\nsrc/app/**/page.tsx                   (edited — async params)\nsrc/app/**/layout.tsx                 (edited — async params)\nsrc/app/**/generateMetadata           (edited — async params)\nsrc/components/**/*.tsx               (edited — deprecated Image props)\n```\n\n## Critères d'acceptation\n\n- `bun run typecheck` se termine avec le code 0 après toutes les étapes.\n- `bun run build` se termine avec le code 0 sans avertissements concernant les API obsolètes.\n- Toutes les routes dynamiques s'affichent correctement dans `bun run dev`.\n- Aucune propriété `params` ou `searchParams` n'est accédée de manière synchrone.\n\n## Commandes de test\n\n```bash\nbun run typecheck\nbun run build\nbun run dev\n# visit several dynamic routes and confirm no runtime errors\ngrep -r \"layout=\\\"fill\\\"\" src/ && echo \"FAIL: deprecated Image prop found\"\ngrep -rn \"cookies()\\|headers()\\|draftMode()\" src/ | grep -v \"await\" && echo \"WARN: unawaited dynamic API\"\n```\n\n## Erreurs courantes de l'IA\n\n- Ignorer l'étape d'audit et effectuer toutes les modifications en une seule passe, provoquant des erreurs difficiles à tracer.\n- Typer les paramètres asynchrones comme `{ params: { slug: string } }` au lieu de `{ params: Promise<{ slug: string }> }`.\n- Oublier de mettre à niveau `@types/react` en même temps que `react`, laissant des incompatibilités de types.\n- Ne pas faire un `await` sur `cookies()` dans une fonction d'aide imbriquée qui elle-même n'est pas asynchrone.\n\n## Invite de correction\n\n```txt title=\"Fix Prompt\"\nThe build fails with type errors on params or a runtime error about cookies/headers.\nFix in order:\n1. For any page or layout receiving `params`, update the prop type to `Promise<{ slug: string }>` and\n   add `const { slug } = await params;` at the top of the function body.\n2. Find every call to `cookies()`, `headers()`, `draftMode()` not preceded by `await` and add it.\n   Make the containing function async if it isn't already.\n3. Run `bun run typecheck` and show me only the remaining errors.\n```"
}