Error: Invariant: Method expects to have requestAsyncStorage, none available
mbj36 opened this issue · 14 comments
Hey, I cloned the repo, followed the readme, but i see this error? Any inputs ?
I have already searched online without any luck
Also, is it mandatory to start the supabase local stack ?
Error: Invariant: Method expects to have requestAsyncStorage, none available
at Object.cookies (webpack-internal:///(sc_server)/./node_modules/.pnpm/next@13.4.7-canary.1_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/client/components/headers.js:46:15)
at NextRouteHandlerAuthStorageAdapter.getCookie (webpack-internal:///(sc_server)/./node_modules/.pnpm/@supabase+auth-helpers-nextjs@0.7.2_@supabase+supabase-js@2.26.0/node_modules/@supabase/auth-helpers-nextjs/dist/index.js:230:42)
at NextRouteHandlerAuthStorageAdapter.getItem (webpack-internal:///(sc_server)/./node_modules/.pnpm/@supabase+auth-helpers-shared@0.4.1_@supabase+supabase-js@2.26.0/node_modules/@supabase/auth-helpers-shared/dist/index.js:261:28)
at eval (webpack-internal:///(sc_server)/./node_modules/.pnpm/@supabase+gotrue-js@2.39.0/node_modules/@supabase/gotrue-js/dist/main/lib/helpers.js:151:37)
at Generator.next (<anonymous>)
at eval (webpack-internal:///(sc_server)/./node_modules/.pnpm/@supabase+gotrue-js@2.39.0/node_modules/@supabase/gotrue-js/dist/main/lib/helpers.js:59:71)
at new Promise (<anonymous>)
at __awaiter (webpack-internal:///(sc_server)/./node_modules/.pnpm/@supabase+gotrue-js@2.39.0/node_modules/@supabase/gotrue-js/dist/main/lib/helpers.js:41:12)
at getItemAsync (webpack-internal:///(sc_server)/./node_modules/.pnpm/@supabase+gotrue-js@2.39.0/node_modules/@supabase/gotrue-js/dist/main/lib/helpers.js:150:38)
at SupabaseAuthClient.eval (webpack-internal:///(sc_server)/./node_modules/.pnpm/@supabase+gotrue-js@2.39.0/node_modules/@supabase/gotrue-js/dist/main/GoTrueClient.js:1356:73)
Error: Invariant: Method expects to have requestAsyncStorage, none available
at Object.cookies (webpack-internal:///(sc_server)/./node_modules/.pnpm/next@13.4.7-canary.1_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/client/components/headers.js:46:15)
at NextRouteHandlerAuthStorageAdapter.getCookie (webpack-internal:///(sc_server)/./node_modules/.pnpm/@supabase+auth-helpers-nextjs@0.7.2_@supabase+supabase-js@2.26.0/node_modules/@supabase/auth-helpers-nextjs/dist/index.js:230:42)
at NextRouteHandlerAuthStorageAdapter.getItem (webpack-internal:///(sc_server)/./node_modules/.pnpm/@supabase+auth-helpers-shared@0.4.1_@supabase+supabase-js@2.26.0/node_modules/@supabase/auth-helpers-shared/dist/index.js:261:28)
at eval (webpack-internal:///(sc_server)/./node_modules/.pnpm/@supabase+gotrue-js@2.39.0/node_modules/@supabase/gotrue-js/dist/main/lib/helpers.js:151:37)
at Generator.next (<anonymous>)
at eval (webpack-internal:///(sc_server)/./node_modules/.pnpm/@supabase+gotrue-js@2.39.0/node_modules/@supabase/gotrue-js/dist/main/lib/helpers.js:59:71)
at new Promise (<anonymous>)
at __awaiter (webpack-internal:///(sc_server)/./node_modules/.pnpm/@supabase+gotrue-js@2.39.0/node_modules/@supabase/gotrue-js/dist/main/lib/helpers.js:41:12)
at getItemAsync (webpack-internal:///(sc_server)/./node_modules/.pnpm/@supabase+gotrue-js@2.39.0/node_modules/@supabase/gotrue-js/dist/main/lib/helpers.js:150:38)
at SupabaseAuthClient.eval (webpack-internal:///(sc_server)/./node_modules/.pnpm/@supabase+gotrue-js@2.39.0/node_modules/@supabase/gotrue-js/dist/main/GoTrueClient.js:793:75)
i had it too but then once i reloaded it went away. for now. not scientific. but app works locally
Closing this, It just worked today
this should not be closed since this is still an issue, even if intermittent. I have this same exact problem, restarting the app and using different browser did not help. :(
this should not be closed since this is still an issue, even if intermittent. I have this same exact problem, restarting the app and using different browser did not help. :(
Try cleaning node_modules and do fresh install
Thanks for the reply.
I tried removing the node_modules and running pnpm install, and also removing the node_modules again and trying npm install
keeps giving me the same error.
Interestingly, build command gives the same error too, so it doesn't seem browser related:
- info Linting and checking validity of types
- info Collecting page data ...[Error: Invariant: Method expects to have requestAsyncStorage, none available]
[Error: Invariant: Method expects to have requestAsyncStorage, none available]
[Error: Invariant: Method expects to have requestAsyncStorage, none available]
Error: Invariant: Method expects to have requestAsyncStorage, none available
at Object.cookies (/Users/lukaszgandecki/projects/vercel-test/supabase-ai-chatbot/.next/server/chunks/243.js:176:15)
at NextRouteHandlerAuthStorageAdapter.getCookie (/Users/lukaszgandecki/projects/vercel-test/supabase-ai-chatbot/.next/server/chunks/101.js:238:42)
at NextRouteHandlerAuthStorageAdapter.getItem (/Users/lukaszgandecki/projects/vercel-test/supabase-ai-chatbot/.next/server/chunks/101.js:572:28)
at /Users/lukaszgandecki/projects/vercel-test/supabase-ai-chatbot/.next/server/chunks/101.js:3819:37
at Generator.next (<anonymous>)
at /Users/lukaszgandecki/projects/vercel-test/supabase-ai-chatbot/.next/server/chunks/101.js:3727:71
at new Promise (<anonymous>)
at __awaiter (/Users/lukaszgandecki/projects/vercel-test/supabase-ai-chatbot/.next/server/chunks/101.js:3709:12)
at getItemAsync (/Users/lukaszgandecki/projects/vercel-test/supabase-ai-chatbot/.next/server/chunks/101.js:3818:38)
at SupabaseAuthClient.<anonymous> (/Users/lukaszgandecki/projects/vercel-test/supabase-ai-chatbot/.next/server/chunks/101.js:2674:73)
Error: Invariant: Method expects to have requestAsyncStorage, none available
at Object.cookies (/Users/lukaszgandecki/projects/vercel-test/supabase-ai-chatbot/.next/server/chunks/243.js:176:15)
at NextRouteHandlerAuthStorageAdapter.getCookie (/Users/lukaszgandecki/projects/vercel-test/supabase-ai-chatbot/.next/server/chunks/101.js:238:42)
at NextRouteHandlerAuthStorageAdapter.getItem (/Users/lukaszgandecki/projects/vercel-test/supabase-ai-chatbot/.next/server/chunks/101.js:572:28)
at /Users/lukaszgandecki/projects/vercel-test/supabase-ai-chatbot/.next/server/chunks/101.js:3819:37
at Generator.next (<anonymous>)
at /Users/lukaszgandecki/projects/vercel-test/supabase-ai-chatbot/.next/server/chunks/101.js:3727:71
at new Promise (<anonymous>)
at __awaiter (/Users/lukaszgandecki/projects/vercel-test/supabase-ai-chatbot/.next/server/chunks/101.js:3709:12)
at getItemAsync (/Users/lukaszgandecki/projects/vercel-test/supabase-ai-chatbot/.next/server/chunks/101.js:3818:38)
at SupabaseAuthClient.<anonymous> (/Users/lukaszgandecki/projects/vercel-test/supabase-ai-chatbot/.next/server/chunks/101.js:2111:75)
[Error: Invariant: Method expects to have requestAsyncStorage, none available]
[Error: Invariant: Method expects to have requestAsyncStorage, none available]
[Error: Invariant: Method expects to have requestAsyncStorage, none available]
fresh clone, npm install, npm run dev:
npm run dev
> @supabase-community/vercel-ai-chatbot@0.0.2 dev
> next dev
- ready started server on 0.0.0.0:3000, url: http://localhost:3000
- info Loaded env from /Users/lukaszgandecki/projects/vercel-test/vercel-chatbot-fork/.env
- warn You have enabled experimental feature (serverActions) in next.config.js.
- warn Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
(node:27376) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
- event compiled client and server successfully in 130 ms (20 modules)
- wait compiling...
- event compiled client and server successfully in 77 ms (20 modules)
- wait compiling /middleware (client and server)...
- event compiled successfully in 329 ms (179 modules)
- wait compiling /sign-in/page (client and server)...
- warn ./node_modules/node-fetch/lib/index.js
Module not found: Can't resolve 'encoding' in '/Users/lukaszgandecki/projects/vercel-test/vercel-chatbot-fork/node_modules/node-fetch/lib'
Import trace for requested module:
./node_modules/node-fetch/lib/index.js
./node_modules/cross-fetch/dist/node-ponyfill.js
./node_modules/@supabase/supabase-js/dist/main/lib/fetch.js
./node_modules/@supabase/supabase-js/dist/main/SupabaseClient.js
./node_modules/@supabase/supabase-js/dist/main/index.js
./node_modules/@supabase/auth-helpers-shared/dist/index.js
./node_modules/@supabase/auth-helpers-nextjs/dist/index.js
./auth.ts
./app/sign-in/page.tsx
./node_modules/node-fetch/lib/index.js
Module not found: Can't resolve 'encoding' in '/Users/lukaszgandecki/projects/vercel-test/vercel-chatbot-fork/node_modules/node-fetch/lib'
Import trace for requested module:
./node_modules/node-fetch/lib/index.js
./node_modules/cross-fetch/dist/node-ponyfill.js
./node_modules/@supabase/supabase-js/dist/main/lib/fetch.js
./node_modules/@supabase/supabase-js/dist/main/SupabaseClient.js
./node_modules/@supabase/supabase-js/dist/main/index.js
./node_modules/@supabase/auth-helpers-shared/dist/index.js
./node_modules/@supabase/auth-helpers-nextjs/dist/index.js
./components/login-button.tsx
Error: Invariant: Method expects to have requestAsyncStorage, none available
at Object.cookies (webpack-internal:///(sc_server)/./node_modules/next/dist/client/components/headers.js:46:15)
at NextRouteHandlerAuthStorageAdapter.getCookie (webpack-internal:///(sc_server)/./node_modules/@supabase/auth-helpers-nextjs/dist/index.js:230:42)
at NextRouteHandlerAuthStorageAdapter.getItem (webpack-internal:///(sc_server)/./node_modules/@supabase/auth-helpers-shared/dist/index.js:261:28)
at eval (webpack-internal:///(sc_server)/./node_modules/@supabase/gotrue-js/dist/main/lib/helpers.js:151:37)
at Generator.next (<anonymous>)
at eval (webpack-internal:///(sc_server)/./node_modules/@supabase/gotrue-js/dist/main/lib/helpers.js:59:71)
at new Promise (<anonymous>)
at __awaiter (webpack-internal:///(sc_server)/./node_modules/@supabase/gotrue-js/dist/main/lib/helpers.js:41:12)
at getItemAsync (webpack-internal:///(sc_server)/./node_modules/@supabase/gotrue-js/dist/main/lib/helpers.js:150:38)
at SupabaseAuthClient.eval (webpack-internal:///(sc_server)/./node_modules/@supabase/gotrue-js/dist/main/GoTrueClient.js:1357:73)
Do you still see issue when running localhost:3000 ?
that's the only thing I tried, dev mode, and the localhost:3000
we still also have it fwiw. but doesnt seem to terminally affect anythign so choosing to ignore for now. fyi @thorwebdev
I am able to reproduce this, and I think it's this Next.js issue: vercel/next.js#45371
The crux it, it's working fine locally, but once deployed to Vercel, it's not working as expected 😭 We're investigating.
fyi we switched everything to nodejs runtime as recommended in #7 and i'm still seeing the same issue. will need to clone this repo from scratch to see if its just me.
@swyxio yes, I'm also still seeing the error messages, however with nodejs runtime functionality seems to be fine. Unfortunately we're still waiting to hear back from Vercel as to what's actually going on here, sorry.
Okay, I think I finally figured this out. Gist is It's very important at what point you call the cookies
method for things to work correctly.
So rather than handing the cookies
method to the supabase client, we need to extract the value first, and then hand the supabase client a function that retrieves that value, e.g.:
'use server'
import { createServerActionClient } from '@supabase/auth-helpers-nextjs'
import { cookies } from 'next/headers'
import { Database } from '@/lib/db_types'
const cookieStore = cookies()
const supabase = createServerActionClient<Database>({
cookies: () => cookieStore
})
thank you!!