-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
Runtime Edge throws an "Invariant: Method expects to have requestAsyncStorage, none available" #52176
Comments
Same deal with cookies() |
@HotCustard do you have a reproduction? I tried running the one in the description, but I could not reproduce this. 🤔 |
@NastykSwED the screenshots look different from the linked reproduction ( |
We cannot recreate the issue with the provided information. Please add a reproduction in order for us to be able to investigate. Why was this issue marked with the
|
@balazsorban44 Fixed! |
Is there a solution for this issue? I'm on Windows as well. ** |
I am getting the same issue 'Invariant: Method expects to have requestAsyncStorage, none available' When using headers(). |
Having the same issue. using cookies for supabase on server side api to receive a webhook. import { cookies } from 'next/headers' const supabase = createServerComponentClient({ cookies }) Getting this error when deployed on vercel |
@balazsorban44 The error can be reproduced by using import { cookies } from "next/headers";
export function middleware() {
cookies();
}
|
I'm getting this same issue now even on 13.4.7, but only when deployed. It works fine locally. |
I had this issue trying to run Clerk Auth on edge on the newest version (13.4.9). It seems to be only in windows environments. I tested the repo in WSL2 and I stopped getting the error. Windows will only work up til 13.4.7. |
Yeah I was also having issues with both clerk Auth and also getting the Invariant: Method expects to have requestAsyncStorage when using headers() on a server components or middleware. It only happens on my windows environment though. Using wsl2 in dev it works okay on version 13.4.9 |
The error still occurs in the latest version of next@13.4.11 on Windows OS. |
Reproduced on 13.4.12 on Windows OS as well Edit: in my case, it was because I was using cookies() in the pages router. OP is not so that's not his issue but if you encounter this issue like me with the pages router, my understanding is that of this version you need to create your own helper function to set cookies. Again, only for the pages router. Pages router just means that your routes are in a directory like "pages/*" instead of app. Do not use cookies() if your api route with pages. |
The issue was solved through this way: #45371 (comment) The issue:In prod, Next.js throws that error message: When it throws the error: When it was fetching data from Supabase database in the server components in prod, not local. Dependencies: "@supabase/auth-helpers-nextjs": "^0.7.3",
"@supabase/supabase-js": "^2.31.0",
"next": "13.4.12",
Operating System:
Platform: linux
Arch: x64
Version: #50-Ubuntu SMP PREEMPT_DYNAMIC Mon Jul 10 18:24:29 UTC 2023
Binaries:
Node: 18.16.0
npm: 9.5.1
Yarn: 1.22.19
pnpm: 8.6.7
Relevant packages:
next: 13.3.0
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0 Dashboard component: import { createServerSupabaseClient, getSession } from "@/components/supabase/supabase-server";
export default async function Dashboard() {
const supabase = createServerSupabaseClient() // this line works well.
const serverSession = await getSession() // this line works well.
const userInfo = serverSession?.user
const pending = await supabase
.from('table')
.select('*', { count: 'exact', head: true })
.eq('username', userInfo.user_metadata.username)
.eq('status', 0)
// Here's the error:
console.log("ERROR [PENDING] DETAILS: ", JSON.stringify(pending, null, 2))
} supabase-server.js: import { cookies } from 'next/headers';
import { cache } from 'react';
import { createServerComponentClient } from '@supabase/auth-helpers-nextjs';
export const createServerSupabaseClient = cache(() =>
createServerComponentClient({ cookies })
)
export async function getSession() {
const supabase = createServerSupabaseClient()
try {
const {
data: { session }
} = await supabase.auth.getSession()
return session
} catch (error) {
console.error('Error:', error)
return null
}
} middleware.js: import { createMiddlewareClient } from '@supabase/auth-helpers-nextjs'
import { NextResponse } from 'next/server'
export async function middleware(req) {
const res = NextResponse.next()
const supabase = createMiddlewareClient({ req, res })
await supabase.auth.getSession()
return res
} Additional:I guess the problem comes from the A comment about this issue from GitHub: #45371 (comment)
|
I also ran into this issue on NextJS 13.4.12, also on windows. For me I encountered the issue when implementing Clerk authentication, specifically when using the ClerkProvider component. Fixed it by reverting to NextJS version 13.4.7. |
The error still occurs in version 13.4.13 |
Issue remains in version 13.4.14-canary.1. It is a windows only bug. It works fine in WSL. reproduction: on Windows, access cookies() on a page with runtime
reproduction where I am actually trying to get this to work: awinogrodzki/next-firebase-auth-edge#80
@balazsorban44 could this reproduction be enough to get this fixed? |
Same problem im middleware.js on windows locally "next": "^13.4.13",
|
The error still occurs in version 13.4.15 and 13.4.15-canary.0 |
Still facing the error on Windows 11 in version 13.4.16 |
The error still occurs in version 13.4.19 and 13.4.20-canary.15 |
The error still occurs in version 13.4.20-canary.40 |
Error still persists on version 13.5.2. I'm on windows and have tried running it normally and using WSL. |
Error also persists in version v13.5.3-canary.0 |
Error also persists in version v13.5.3 |
Same error for me. Has a fix been identified? Node version = v18.12.1 Use case:
|
I downgraded next to 13.5.3 and it works. |
Tried Next 13.5.3 with Node 18 on Windows 11, still no luck for me. |
I am still facing the same issue with Next 13.5.5-canary.4 with Node 18 and Windows 11. With this bug, I can not declare any page as runtime edge for local development when working on Windows. |
I can confirm that @oliver-oloughlin's solution is right. It worked for me as well on 13.4.7. |
I'm getting this error running |
"next": "13.5.5-canary.14",also solves the problem |
@w3nder thank you, but it's not working for me, still failing with
|
Also still broken for me, tested with 13.5.5-canary.17
|
I got the same error and I got it working somehow. I tried many things, but these were my last two steps. I did:
Now calling the supabase server function like this in my React component. It looks a bit ugly because of the await (await ..)
I hope this works for others as well |
This is more a platform related issue. So the localhost at windows machine was having this issue. I was able to resolve it by adding this line in app/page.js file export const runtime = 'nodejs'; |
@azeemasim01 Yeah, but that's exactly the issue, runtime edge on windows causes the bug. I am using the edge runtime, so switching to nodejs is not a solution for me or anyone committed to edge. |
I'm also facing this issue. The error only occured on dynamic route (app router). Example: Works perfectly:
On dynamic route, it throws the error
the
there is my
I'm working with What I found until now: The
comparing to an ok:
so it seems that the AsyncLocalStorage is disabled
I prepared a little repository to replicate the issue: https://github.com/joachimjusth/nextjs-issue-52176 I hope it'll help |
I have the exact same issue with Next 14.0.4 where a catch all route that only returns a "NotFound" page causes the issue... I am still looking for a workaround because it is annoying because I use a headless CMS and this is the entry point for editors to see their changes that are not approved an published yet |
We've added a lot of improvements since this issue was opened, It looks like that comments have somewhat deviated from the original report, (which I verified working fine on In most cases, the issue is that you are calling Please upgrade, and if you are still having issues, open a new bug report with a minimal reproduction, thanks! 🙏 (Note, a minimal reproduction means you don't assume the maintainer to register for third-party services, setting up env. secrets etc., unless it's really necessary to reproduce the bug.) |
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true), Metadata (metadata, generateMetadata, next/head, head.js), Middleware / Edge (API routes, runtime)
Link to the code that reproduces this issue or a replay of the bug
https://github.com/NastykSwED/next-edge-invariant-error
To Reproduce
pnpm install
pnpm dev
Go to localhost:3000
Look at terminal, see error:
Describe the Bug
When using the runtime edge, if we use the
headers()
functions from "import { headers } from 'next/headers'
", this error occurs, not only inlayout.tsx | jsx
files but also inpage.tsx | jsx
files and ingenerateMetadata
functions. The error does not occur in older versions such asnext@13.4.7
:layout.tsx file
page.tsx file
generateMetadata function
Expected Behavior
It would be expected that when using the runtime edge this error would not occur. In earlier versions such as next@13.4.7 it works correctly.
Which browser are you using? (if relevant)
Microsoft Edge 114.0.1823.67
How are you deploying your application? (if relevant)
The text was updated successfully, but these errors were encountered: