-
Notifications
You must be signed in to change notification settings - Fork 27k
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
[NEXT-644] cookies broke on 13.2.1 Invariant: Method expects to have requestAsyncStorage, none available #46356
Comments
Not sure if its related but happens when I access cookies() outside of an async function.
|
In order to access |
This marks all pages in development as supporting dynamic HTML. Detection for runtime violations of dynamic generation is completed during the production build. Fixes #46356 fix NEXT-644 ([link](https://linear.app/vercel/issue/NEXT-644)) Co-authored-by: Tim Neutkens <[email protected]> Co-authored-by: JJ Kasper <[email protected]>
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 Fixed it by also providing |
@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. |
@frankimhof Where exactly is this file and how are you calling user session? |
@talbertherndon |
This would not work for me because I'm using |
You get the request out of the context passed to getServersideProps' context. |
I know, but this is on an API: https://github.com/Global-Conflicts-ArmA/global-conflicts-website/blob/6412171e640ebbff34c99f60d37fc5387554c66e/pages/api/missions/%5BuniqueName%5D/update.ts#L89 I'm trying some hacks to see if I can get the session there. |
is this still an issue in @latest? ├─┬ @next-auth/[email protected] I am getting the error with this (in pages/api): import { cookies } from 'next/headers'; export default async function handler(req, res) { Error: error - node_modules\next\dist\client\components\headers.js (56:14) @ cookies |
I am getting this error on latest and with canary. |
@reesmanp nice to know it is not just me. is this broken for everyone? are other just getting the cookie on the front end? i am wondering why others aren't speaking up. i would hate to downgrade to 12.x. |
Same here. Trying to access headers but having this issue too. |
I get it in my Root Layout in nextjs 13
Here is the error
|
I don't think you need to downgrade. Since this is the app directory and in 13 you don't need to use the app directory and the pages directory is stable, you can maintain using 13. We're using v13 on pages but are looking to migrate to app. |
@wyattjoh it looks like the code path for retrieving cookies and headers calls |
Downgrading to 13.2.0 (from 13.4.0), it works. |
thanks @reesmanp for sharing your insight about this issue. i was pretty sure I tried 13.2.0 before but just did so again and am getting the same error: error - node_modules\next\dist\client\components\headers.js (34:14) @ cookies ├─┬ @next-auth/[email protected] |
on the latest 13.4.1 release, having the same issue. |
Having this issue as well, using server actions on 13.4.1 release |
Having the same issue with server actions on 13.4.1 with |
@lk9100 @salvinoto @SvemirskiHod just upgrade NextJS to the v13.4.2-canary.3 version. |
have just installed v13.4.2-canary.3 |
^^ Also on 13.4.2-canary.3 and getting the same error when invoking |
I am also getting the same error. |
Hey, could you open a new issue with a reproduction so that we can have a look? |
i can't reproduce this anymore after a clean npm install with latest canary. @timneutkens thanks for the heads up 👍 |
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. |
@timneutkens https://github.com/lukevers/next-644 OK so I initially had I have two pages that define two situations:
|
@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-auth
export async function getSession() {
return await getServerSession({});
}
// uses a copied version locally
export async function __unstable__getSession() {
return await __internal__unstable__getSession({});
} Is there anyway this could somehow be related to the bundler? On local version: 'use server';
import { __unstable__getSession } from "@/util/session";
export default async function ServerExample(message: string) {
return await __unstable__getSession();
} using the library's function: 'use server';
import { getSession } from '@/util/session';
export default async function ServerExample(message: string) {
return await getSession();
} |
i only get this error when any of the server actions from a single file is imported inside client component |
Can we re-open the issue? This error is still happening in |
What I did to solve the problem is replacing the entire cookies implementation from NextJS with the cookies-next library. |
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 🙏 |
Verify canary release
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: Ubuntu 20.04.0 LTS Fri Feb 24 2023 12:23:18 GMT+0200 (Eastern European Standard Time)
Binaries:
Node: 16.14.2
npm: 7.17.0
Yarn: 1.22.19
pnpm: 7.13.6
Relevant packages:
next: 13.2.1
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to the code that reproduces this issue
https://stackblitz.com/edit/vercel-next-js-gqeapg?file=package.json,app%2F[variant]%2F(shop)%2Fp%2F[[...id]]%2Fpage.tsx,next.config.js
To Reproduce
Try to import cookies from
next/headers
Try to access a dynamic page, eg
/test/p
Describe the Bug
Error: Invariant: Method expects to have requestAsyncStorage, none available
This happens if I do an import of cookies
Expected Behavior
I can access the cookies object on a dynamic page
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
NEXT-644
The text was updated successfully, but these errors were encountered: