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:
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.
@@ -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.
Ask the installed
nextwhatcookies()returnsRun 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/headersasks for the import path your code uses. With--pkg next, Lockdocs answersnot_exported, because the package root doesn’t exportcookies, and lists other import paths, includingnext/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 auditreported a moderate advisory fornext@15.5.29that 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/headersnpm may print
ERESOLVE overriding peer dependencywhile 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; setLOCKDOCS_EMBED=0to keep search keyword-only. Once the tool and docs are cached, add--offlineto skip downloads. The declaration still comes fromnode_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 ascookies().get('name')?.value. On 15.5.29, the answer citesnext@15.5.29 upstream:docs/01-app/03-api-reference/03-file-conventions/route.mdx:125andnext@15.5.29 upstream:docs/01-app/03-api-reference/04-functions/cookies.mdx:1.Fix the call site
By hand: make the Server Component
asyncand awaitcookies(), as in the diff above. TypeScript also accepts the awaited form on Next.js 14.2.35 (tscexit 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 okThe 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-errorcomment and may add a temporaryUnsafeUnwrappedCookiescast. Search for both before you ship.Check it
Type-check the project npx tsc --noEmitActual 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,
tscprints nothing and exits with code 0.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 setupsetupdetects 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 mcpFor 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’sapitool 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 asroot. 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:
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
{
"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.
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>
}{
"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"]
}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/headersContinue from the upgrade commands in step 1. Neither install needs --force or --legacy-peer-deps.