next.js: [NEXT-1090] Property 'set' does not exist on type 'ReadonlyRequestCookies'.

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: linux
      Arch: x64
      Version: #1 SMP PREEMPT_DYNAMIC Thu Apr  6 19:47:04 UTC 2023
    Binaries:
      Node: 18.16.0
      npm: 9.5.1
      Yarn: 1.22.19
      pnpm: 8.3.1
    Relevant packages:
      next: 13.4.1-canary.1
      eslint-config-next: 13.4.1-canary.1
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/divine-firefly-4si8qm?file=%2Fpackage.json

To Reproduce

https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions#using-headers

Describe the Bug

The docs state that we can set cookies within a server action. but it’s readonly

image

https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions#using-headers

Expected Behavior

I want to be able to do what the docs says: https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions#using-headers

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-1090

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 18
  • Comments: 33 (3 by maintainers)

Commits related to this issue

Most upvoted comments

This should be a TypeScript error as the .set method is missing. If you add // @ts-ignore it should pass build with latest canary version.

Will find a way to fix it properly.

Seems to be working on v13.4.1

I’m using 13.4.1 and for me it’s not working

is there any update on this ??

I have the same problem

Ok I believe the confusion is between imported server action files vs in component server actions.

This currently works fine for inline server actions where use server directive is at the top of the function body.

It throws the requestAsyncStorage error for actions defined with top-level use server directive on top of a file.

cookies().set using Next.js v13.4.2-canary.2 in server action doesn’t work for me

Error: ReadonlyRequestCookies cannot be modified.

What about setting Http-only cookies? How do I set Http-only cookies?

@sujang958 You’ll have to move to latest release https://github.com/vercel/next.js/releases/tag/v13.4.4-canary.0

And @josias-r no, it shouldn’t be reopened.

@john-griffin Not sure I follow. But you’re working so we’re good. 😎 I updated my repo with more examples of some cross usage.

@johnson-jesse thats working great! I paired my example down to match and it seems ok now. It seems like something was being cached somewhere. Cheers!

This should be a TypeScript error as the .set method is missing. If you add // @ts-ignore it should pass build with latest canary version.

Will find a way to fix it properly.

Adding the @ts-ignore directive is allowing my build to pass now. Great! Looking forward to proper support.

cookies().set is working for me in a server action using the next@13.4.2-canary.2

✅ Confirmed. This is working in 13.4.2-canary.2 and 13.4.2-canary.3. The typescript error still shows, but the app should still work. I no longer see the runtime error as show above.

Error: Invariant: Method expects to have requestAsyncStorage, none available at persistCookieState

I see the cookie set in the browser as expected via server action. Now if we can just get that TS error and the rest of those console warnings cleaned up, we’ll be a happy crew.

I’m still having the same problem, but I noticed in the .pnpm file for the definitions, that the set value was omitted in the Typescript utility:

/// <reference types="node" /> import type { RequestCookies } from '../cookies'; import type { BaseNextResponse } from '../../../base-http'; import type { ServerResponse } from 'http'; import { ResponseCookies } from '../cookies'; export declare type ReadonlyRequestCookies = Omit<RequestCookies, 'clear' | 'delete' | 'set'>; export declare class RequestCookiesAdapter { static seal(cookies: RequestCookies): ReadonlyRequestCookies; } export declare const SYMBOL_MODIFY_COOKIE_VALUES: unique symbol; export declare class MutableRequestCookiesAdapter { static seal(cookies: RequestCookies, res: ServerResponse | BaseNextResponse | undefined): ResponseCookies; }

maybe is something with those definitions, I dont know…