Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Invariant: Method expects to have requestAsyncStorage, none available #6989

Closed
bengrau opened this issue Mar 17, 2023 · 6 comments
Closed
Labels
incomplete Insufficient reproduction. Without more info, we won't take further actions/provide help. triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@bengrau
Copy link

bengrau commented Mar 17, 2023

Environment

System:
OS: macOS 11.6.1
CPU: (8) x64 Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz
Memory: 658.60 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 18.0.0 - /usr/local/bin/node
npm: 8.19.2 - /usr/local/bin/npm
Browsers:
Brave Browser: 111.1.49.120
Chrome: 111.0.5563.64
Firefox: 110.0.1
Firefox Developer Edition: 112.0
Safari: 15.0

Reproduction URL

next-auth-example

Describe the issue

I am coding in VS Code. If I want to debug everything is working fine but if I call const session = await getServerSession(authOptions) I get the error "Error: Invariant: Method expects to have requestAsyncStorage, none available".

I am using the following Debug Config:

{ "version": "0.2.0", "configurations": [ { "name": "Next.js: debug server-side", "type": "node-terminal", "request": "launch", "command": "npm run dev" }, ] }

How to reproduce

Please use the above VS Code launch.json settings and debug a next.js project. When calling a page.tsx with const session = await getServerSession(authOptions) you should get the same error.

Expected behavior

I would expect to be able to debug the session variable here.

@bengrau bengrau added the triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. label Mar 17, 2023
@balazsorban44 balazsorban44 added the incomplete Insufficient reproduction. Without more info, we won't take further actions/provide help. label Mar 19, 2023
@nextauthjs nextauthjs deleted a comment from github-actions bot Mar 20, 2023
@balazsorban44
Copy link
Member

This error comes from Next.js and not next-auth.

You can try following one of these issues:

vercel/next.js#46356
vercel/next.js#45371

@Divinebosst
Copy link

Divinebosst commented Jun 14, 2023

Make sure you are not importing a Server component into a Client Component. In my case, I was using getServerSession in a Navbar Component, which was then imported into the root page.jsx (client component) and it triggered that error (Next.js v13.4.5 and Next-Auth v4.22.1)

@jmilus
Copy link

jmilus commented Jun 30, 2023

Does this extend to a Server Component being a child of a Client Component (Client wrapping Server)?
If so, how do I use Context wrappers with pages?

@Divinebosst
Copy link

No, this only happened when I directly imported a Server component into a Client component.

@yarabramasta
Copy link

Make sure you are not importing a Server component into a Client Component. In my case, I was using getServerSession in a Navbar Component, which was then imported into the root page.jsx (client component) and it triggered that error (Next.js v13.4.5 and Next-Auth v4.22.1)

In my case, if i tryna use page.tsx with 'use client' it will cause that error. I'm using next v13.4.10 and next-auth v4.22.3

@bookinlife
Copy link

i use nextauth, and i solve it by server action.

"use server"; export const LoginOut = async () => { await signOut(); };
import into client compoent:
<form action={LoginOut}> <button> Sign Out</div> </button> </form>

form is needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
incomplete Insufficient reproduction. Without more info, we won't take further actions/provide help. triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

6 participants