LOCKDOCS / RECIPE

Next.js 15 made cookies() async: fix cookies().get()

In Next.js 15, cookies() from next/headers returns a Promise. Code that calls cookies().get() type-checks on Next.js 14 and fails on 15. Check what the next package you installed declares, then fix the call site.

The change

A Server Component that calls cookies().get("session") type-checks on Next.js 14. On Next.js 15, tsc fails:

Actual output: tsc on Next.js 15.5.29
app/account/page.tsx(8,27): error TS2339: Property 'get' does not exist on type 'Promise<ReadonlyRequestCookies>'.

This recipe moves one file, app/account/page.tsx, from Next.js 14.2.35 to 15.5.29. It uses Lockdocs to read the cookies() declaration from the next package in node_modules, so neither you nor your coding agent has to rely on memory.

Actual output: git diff after the codemod (step 2)
@@ -3,9 +3,9 @@ import { redirect } from "next/navigation"
 
 // Only signed-in users can open this page.
 
-export default function AccountPage() {
+export default async function AccountPage() {
   // Read the session cookie set at sign-in.
-  const token = cookies().get("session")
+  const token = (await cookies()).get("session")
   if (!token) redirect("/sign-in")
   return <h1>Your account</h1>
 }

The account page is a synthetic type-check example, not production authentication. A session cookie being present doesn’t prove who the visitor is.

Next.js 14.2.35

export declare function cookies(): ReadonlyRequestCookies

dist/client/components/headers.d.ts:13

Next.js 15.5.29

export declare function cookies(): Promise<ReadonlyRequestCookies>

dist/server/request/cookies.d.ts:24

Next.js documents this in Async Request APIs (breaking change) and the cookies API reference.

  1. Ask the installed next what cookies() returns

    Run this from the folder that contains your lockfile, after npm install:

    Look up cookies() in next/headers
    npx -y @sylphx/lockdocs@0.7.12 api cookies --pkg next/headers

    --pkg next/headers asks for the import path your code uses. With --pkg next, Lockdocs answers not_exported, because the package root doesn’t export cookies, and lists other import paths, including next/headers.

    Actual output: Next.js 14 project
    next@14.2.35 · npm · node_modules/next · pinned in package-lock.json
    Upstream: github.com/vercel/next.js@v14.2.35 commit 7b940d9ce96faddb9f92ff40f5e35c34ace04eb2 (317 files)
    Public import: `next/headers` · symbol `cookies`
    
    Declaration entrypoint: headers.d.ts (legacy)
    
    ### cookies (function) — next@14.2.35 dist/client/components/headers.d.ts:13
    ```ts
    export declare function cookies(): ReadonlyRequestCookies
    ```

    Now upgrade. Use the latest patch in the 15.x line, which was 15.5.29 (npm tag backport) when this was written. In our run, npm audit reported a moderate advisory for next@15.5.29 that is fixed in Next.js 16. Check current Next.js advisories before you choose a version for a deployed application.

    Upgrade, then look up cookies() again
    npm install next@15.5.29 react@19.3.1 react-dom@19.3.1
    npm install -D @types/react@19.3.3
    npx -y @sylphx/lockdocs@0.7.12 api cookies --pkg next/headers

    npm may print ERESOLVE overriding peer dependency while React 18 is being replaced. In our run the install still completed with exit code 0.

    Actual output: same project on Next.js 15.5.29
    next@15.5.29 · npm · node_modules/next · pinned in package-lock.json
    Upstream: github.com/vercel/next.js@v15.5.29 commit 17014e9cf7891cc353ebfd8fb4a407f9e4cbbf47 (372 files)
    Public import: `next/headers` · symbol `cookies`
    
    Declaration entrypoint: headers.d.ts (legacy)
    
    ### cookies (function) — next@15.5.29 dist/server/request/cookies.d.ts:24
    ```ts
    export declare function cookies(): Promise<ReadonlyRequestCookies>
    ```

    The Upstream: line names the public Next.js docs that Lockdocs downloaded from GitHub for that exact release tag on its first query in the project. The first query can also download a 130 MB embedding model once; set LOCKDOCS_EMBED=0 to keep search keyword-only. Once the tool and docs are cached, add --offline to skip downloads. The declaration still comes from node_modules.

    To get the guide text for your version as well as the signature:

    Ask the Next.js docs for your version
    npx -y @sylphx/lockdocs@0.7.12 next "is cookies() async"

    Actual output, excerpt: on 14.2.35, the top section is the Server Actions example from next@14.2.35 upstream:docs/02-app/01-building-your-application/02-data-fetching/02-server-actions-and-mutations.mdx:854, written as cookies().get('name')?.value. On 15.5.29, the answer cites next@15.5.29 upstream:docs/01-app/03-api-reference/03-file-conventions/route.mdx:125 and next@15.5.29 upstream:docs/01-app/03-api-reference/04-functions/cookies.mdx:1.

  2. Fix the call site

    By hand: make the Server Component async and await cookies(), as in the diff above. TypeScript also accepts the awaited form on Next.js 14.2.35 (tsc exit code 0), so you can merge the fix before you bump the version.

    With the official codemod: commit your changes first, so the codemod runs in a clean git working tree. Review its diff before you keep it.

    Run the Next.js codemod
    npx @next/codemod@16.4.6 next-async-request-api .
    Actual output: @next/codemod 16.4.6
    Results: 
    0 errors
    0 unmodified
    0 skipped
    1 ok

    The diff it produced is the one at the top of this page. If the codemod can’t migrate a call automatically, it adds an @next-codemod-error comment and may add a temporary UnsafeUnwrappedCookies cast. Search for both before you ship.

  3. Check it

    Type-check the project
    npx tsc --noEmit
    Actual output: Next.js 15.5.29 before the fix (exit code 2)
    app/account/page.tsx(8,27): error TS2339: Property 'get' does not exist on type 'Promise<ReadonlyRequestCookies>'.

    After the fix, tsc prints nothing and exits with code 0.

  4. Let Cursor or Claude Code read the same declaration

    Connect Lockdocs to your editor once:

    Configure your MCP clients
    npx -y @sylphx/lockdocs@0.7.12 setup

    setup detects Claude Code, Codex, Cursor, VS Code, Claude Desktop, Windsurf and Gemini CLI, writes their MCP config and prints every change. If you only use Claude Code:

    Claude Code
    claude mcp add lockdocs -- npx -y @sylphx/lockdocs@0.7.12 mcp

    For Cursor, use the one-click install link in the Lockdocs README or add the server to .cursor/mcp.json:

    .cursor/mcp.json
    {
      "mcpServers": {
        "lockdocs": { "command": "npx", "args": ["-y", "@sylphx/lockdocs", "mcp"] }
      }
    }

    Then ask:

    Prompt for your editor
    Use lockdocs: what does `cookies()` from `next/headers` return in this project? Cite the declaration.

    The citation should match step 1: next@15.5.29 dist/server/request/cookies.d.ts:24. When we called the MCP server’s api tool directly with the same project, it returned that line. If your editor shows a different version, it is reading another folder: pass the absolute path of the folder with your lockfile as root. Up-to-date docs for Cursor and Claude Code covers each step.

Optional: list every affected call site before you bump

From the Next.js 14 project:

Upgrade report
npx -y @sylphx/lockdocs@0.7.12 upgrade next 15.5.29 --fetch

--fetch downloads exactly next@15.5.29 from the npm registry so Lockdocs can compare it with the installed version. Without it, Lockdocs won’t compare against the version in node_modules; it asks you to add --fetch. The full report lists each changed API, its replacement and your call sites. It is part of Lockdocs Pro. Without a licence, the command prints a one-line summary with one sample call site and exits with code 3.

Illustrative: the Playground has a preview of the report for this change. It is a bundled example (next@14.2.3 → next@15.0.0, app/account/page.tsx:8), not a scan of your code. See the Next.js 14 → 15 report preview

Reproduce this recipe

account-next14/package.json
{
  "name": "account-next14",
  "private": true,
  "dependencies": {
    "next": "14.2.35",
    "react": "18.3.1",
    "react-dom": "18.3.1"
  },
  "devDependencies": {
    "@types/node": "20.17.6",
    "@types/react": "18.3.12",
    "typescript": "5.6.3"
  }
}

account-next14/app/account/page.tsx is the “before” file; the cookies() call is on line 8. The account page is a synthetic type-check example, not production authentication. A session cookie being present doesn’t prove who the visitor is.

account-next14/app/account/page.tsx
import { cookies } from "next/headers"
import { redirect } from "next/navigation"

// Only signed-in users can open this page.

export default function AccountPage() {
  // Read the session cookie set at sign-in.
  const token = cookies().get("session")
  if (!token) redirect("/sign-in")
  return <h1>Your account</h1>
}
account-next14/tsconfig.json
{
  "compilerOptions": {
    "target": "ES2017",
    "lib": ["dom", "dom.iterable", "esnext"],
    "strict": true,
    "noEmit": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "jsx": "preserve",
    "skipLibCheck": true,
    "isolatedModules": true,
    "esModuleInterop": true
  },
  "include": ["app/**/*.tsx"]
}
Install and check on Next.js 14
cd account-next14
npm install            # writes package-lock.json; Lockdocs reads the pinned version from it
npx tsc --noEmit       # exit code 0 on 14.2.35
npx -y @sylphx/lockdocs@0.7.12 api cookies --pkg next/headers

Continue from the upgrade commands in step 1. Neither install needs --force or --legacy-peer-deps.