nextjs - ✅(Solved) Fix Docs: .clear() method in cookies [1 pull requests, 3 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#86778Fetched 2026-04-08 02:09:20
View on GitHub
Comments
3
Participants
3
Timeline
12
Reactions
0
Author
Assignees
Timeline (top)
commented ×3assigned ×1closed ×1cross-referenced ×1

Fix Action

Fixed

PR fix notes

PR #86788: docs: cookie clear and has alignment

Description (problem / solution / changelog)

Closes: https://github.com/vercel/next.js/issues/86778

Changed files

  • docs/01-app/03-api-reference/04-functions/cookies.mdx (modified, +1/-2)
  • docs/01-app/03-api-reference/04-functions/next-request.mdx (modified, +1/-1)
  • docs/01-app/03-api-reference/04-functions/next-response.mdx (modified, +11/-0)

Code Example

import { cookies } from "next/headers";
import { NextResponse } from "next/server";

export async function POST() {
  const cookieStore = await cookies();

  cookieStore.clear(); //Property 'clear' does not exist on type 'ReadonlyRequestCookies'.ts(2339)

  return NextResponse.json({ success: true });
}
RAW_BUFFERClick to expand / collapse

What is the documentation issue?

Documentation mentions .clear() method in cookies, but cookies return type doesn't have clear method defined. When I took a look at source code I saw .clear method intentionally excluded from type

Is there any context that might help us understand?

"next": "16.0.7"

cookies used in route handlers. Code snippet

import { cookies } from "next/headers";
import { NextResponse } from "next/server";

export async function POST() {
  const cookieStore = await cookies();

  cookieStore.clear(); //Property 'clear' does not exist on type 'ReadonlyRequestCookies'.ts(2339)

  return NextResponse.json({ success: true });
}

Does the docs page already exist? Please link to it.

https://arc.net/l/quote/wtrfjpau

extent analysis

TL;DR

The issue can be resolved by using an alternative approach to clear cookies, as the clear() method is intentionally excluded from the cookies type.

Guidance

  • The error message indicates that the clear() method does not exist on the ReadonlyRequestCookies type, which is returned by the cookies() function.
  • To clear cookies, you can try using the Set-Cookie header with an expiration date in the past, effectively deleting the cookie.
  • You can use the NextResponse object to set the Set-Cookie header, for example: NextResponse.headers.set("Set-Cookie", "cookie-name=; expires=Thu, 01 Jan 1970 00:00:00 GMT").
  • Verify that the cookie is cleared by checking the response headers or using a tool like the browser's developer tools to inspect the cookies.

Example

import { cookies } from "next/headers";
import { NextResponse } from "next/server";

export async function POST() {
  const cookieStore = await cookies();
  const response = NextResponse.json({ success: true });
  response.headers.set("Set-Cookie", "cookie-name=; expires=Thu, 01 Jan 1970 00:00:00 GMT");
  return response;
}

Notes

The provided code snippet is for Next.js version "16.0.7", and the solution may not apply to other versions.

Recommendation

Apply workaround: The clear() method is intentionally excluded from the cookies type, so using an alternative approach like setting the Set-Cookie header is the recommended solution.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING