You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[NEXT-644] cookies broke on 13.2.1 Invariant: Method expects to have requestAsyncStorage, none availableΒ #46356
changed the title [-]cookies broke on 13.2.1 Invariant: Method expects to have requestAsyncStorage, none available[/-][+][NEXT-644] cookies broke on 13.2.1 Invariant: Method expects to have requestAsyncStorage, none available[/+]on Feb 27, 2023
Not sure if its related but happens when I access cookies() outside of an async function.
import { cookies } from 'next/headers';
//gives same error when used here
const hello = cookies().get('access_token')?.value;
export default async function FeedbackPage(props: FeedbackPageProps) {
//works ok inside here
....
...
}
Reacted by Kai Lan, Roy Ossai, BαΊ£o HΓ . and kai Imasato
I am using experimental App directory (appDir: true).
I got the error when calling getServerSession(authOptions) (imported from next-auth) inside of an API Route handler function.
Fixed it by also providing req and res (from the API Route handler) as arguments to getServerSession: getServerSession(req, res, authOptions)
This would not work for me because I'm using getServerSession inside a multer fileFilter function, I don't have access to the response there. At least not that I'm aware.
Hey @timneutkens, let me see if I can get a reproduction for you, but I just got this same error while testing transitioning a server action passed down from the page to a client component to having the client component have direct access to it. I just upgraded my dependencies and see this exact issue.
OK so I initially had cookies().get('anything'); which did cause issues, but not on 13.4.2-canary.5. I do still get these errors, but not with cookies directly, I get them when I'm using getServerSession from import { getServerSession } from 'next-auth/next'; -- I'm not sure if this is a nextjs issue or a next-auth issue since cookies directly seem to work OK.
I have two pages that define two situations:
/issue1 - "individual server components" - The main issue here is that when we access cookies through a server component imported from a client component, it does not work. It works if we import it in a server component (page layout here) and pass it to the client component as a prop.
/issue2 - "shared server component" - The issue here is that when we access cookies through a server component imported from a client component, it does not work. It also does not work even if it was passed through to the client component if the server component is the same component
@timneutkens I came to the conclusion this is related to next-auth after my related closed issue (here), but I wanted to debug it more so I copied the code locally and when I use the same code (but not imported from the library), grabbing my session information works.
import{getServerSession}from'next-auth/next';import{__internal__unstable__getSession}from'./_internal_session';// uses from next-authexportasyncfunctiongetSession(){returnawaitgetServerSession({});}// uses a copied version locallyexportasyncfunction__unstable__getSession(){returnawait__internal__unstable__getSession({});}
Is there anyway this could somehow be related to the bundler?
Please see my earlier comment, we can investigate if you provide a reproduction in a new issue, instead you're posting additional comments here without a reproduction π’ Thank you very much π #46356 (comment)
Activity
[-]cookies broke on 13.2.1 Invariant: Method expects to have requestAsyncStorage, none available[/-][+][NEXT-644] cookies broke on 13.2.1 Invariant: Method expects to have requestAsyncStorage, none available[/+]ayhanap commentedon Mar 1, 2023
Not sure if its related but happens when I access cookies() outside of an async function.
wyattjoh commentedon Mar 6, 2023
In order to access
cookies(), it must be done inside a component or a route, you can't access it from the global scope @ayhanap.Marks app paths in dev as supporting dynamic html (#46848)
frankimhof commentedon Mar 31, 2023
I also got this error, but was able to fix it.
I am using experimental App directory (appDir: true).
I got the error when calling
getServerSession(authOptions)(imported from next-auth)inside of an API Route handler function.
Fixed it by also providing
reqandres(from the API Route handler) as arguments togetServerSession:getServerSession(req, res, authOptions)jgb-solutions commentedon Apr 12, 2023
@frankimhof hey thank you! This helps me get tRPC working with next 13 app dir. <3 I was having a hard time getting the session for the context.
talbertherndon commentedon Apr 13, 2023
@frankimhof Where exactly is this file and how are you calling user session?
jgb-solutions commentedon Apr 13, 2023
@talbertherndon
import { ServerResponse } from "http"VyMajoris commentedon Apr 15, 2023
This would not work for me because I'm using
getServerSessioninside a multerfileFilterfunction, I don't have access to the response there. At least not that I'm aware.jgb-solutions commentedon Apr 15, 2023
You get the request out of the context passed to getServersideProps' context.
12 remaining items
SvemirskiHod commentedon May 9, 2023
Having the same issue with server actions on 13.4.1 with
next-auth'sgetServerSessionas well as withcookiesandheadersfrom "next/headers"vitalyliber commentedon May 9, 2023
@lk9100 @salvinoto @SvemirskiHod just upgrade NextJS to the v13.4.2-canary.3 version.
lk9100 commentedon May 9, 2023
@vitalyliber
have just installed v13.4.2-canary.3
same error
tmns commentedon May 10, 2023
^^ Also on 13.4.2-canary.3 and getting the same error when invoking
getServerSessionfrom a server action.hgogoi2012 commentedon May 11, 2023
I am also getting the same error.
timneutkens commentedon May 11, 2023
Hey, could you open a new issue with a reproduction so that we can have a look?
lk9100 commentedon May 11, 2023
i can't reproduce this anymore after a clean npm install with latest canary.
@timneutkens thanks for the heads up π
lukevers commentedon May 11, 2023
Hey @timneutkens, let me see if I can get a reproduction for you, but I just got this same error while testing transitioning a server action passed down from the page to a client component to having the client component have direct access to it. I just upgraded my dependencies and see this exact issue.
lukevers commentedon May 11, 2023
@timneutkens https://github.com/lukevers/next-644
OK so I initially had
cookies().get('anything');which did cause issues, but not on13.4.2-canary.5. I do still get these errors, but not with cookies directly, I get them when I'm usinggetServerSessionfromimport { getServerSession } from 'next-auth/next';-- I'm not sure if this is a nextjs issue or a next-auth issue since cookies directly seem to work OK.I have two pages that define two situations:
/issue1- "individual server components" - The main issue here is that when we access cookies through a server component imported from a client component, it does not work. It works if we import it in a server component (page layout here) and pass it to the client component as a prop./issue2- "shared server component" - The issue here is that when we access cookies through a server component imported from a client component, it does not work. It also does not work even if it was passed through to the client component if the server component is the same componentlukevers commentedon May 11, 2023
@timneutkens I came to the conclusion this is related to next-auth after my related closed issue (here), but I wanted to debug it more so I copied the code locally and when I use the same code (but not imported from the library), grabbing my session information works.
Is there anyway this could somehow be related to the bundler?
lukevers/next-644@ca99b9e
On
/localin that repo, both of the buttons work now. The difference here between this one and the previous one is:local version:
using the library's function:
ammarrik commentedon May 13, 2023
i only get this error when any of the server actions from a single file is imported inside client component
Hiieu commentedon May 20, 2023
Can we re-open the issue? This error is still happening in
v13.4.4-canary.0.Hiieu commentedon May 21, 2023
What I did to solve the problem is replacing the entire cookies implementation from NextJS with the cookies-next library.
timneutkens commentedon May 22, 2023
Please see my earlier comment, we can investigate if you provide a reproduction in a new issue, instead you're posting additional comments here without a reproduction π’ Thank you very much π
#46356 (comment)