Next.js Discord

Discord Forum

Invariant: cookies() expects to have requestAsyncStorage, none available.

Answered
Somebody posted this in #help-forum
Open in Discord
Avatar
Is cookies() not supported on the edge runtime? The docs make it seem like it is (although it isn't clarified), however I'm getting this error when trying to run my application locally.
Could it be a missing dependency or something?

25 Replies

Avatar
European sprat
What version of next
Avatar
latest
13.4.19
Avatar
European sprat
i just tried on a route handler where i set it to const runtime = "edge" and reading cookies worked
where are you trying to read them?
Avatar
in the root layout
it works with the nodejs runtime, but not with the edge runtime
I'm calling cookies() in the root layout, then pass the return value to a client component, which is a context provider to pass them to other components.
Apparently this worked in 13.2.0, according to a github issue
Avatar
It works in 13.4.7 too, just tested it out
Avatar
European sprat
i just tried a new create-next-app at it works
Avatar
broken in 13.4.17 and 13.4.19
Avatar
European sprat
Image
all i did was add the runtime export and logged out the cookies and i can see them
tested with prod build too
Avatar
I'll try to reproduce it with a smaller code base
Avatar
Still happening with only this code:

// app/layout.tsx
import { Noto_Sans } from "next/font/google";
import { cookies } from "next/headers";

const font = Noto_Sans({
  weight: ["200", "300", "400"],
  subsets: ["latin"],
});

export const runtime = "edge";

const RootLayout = async ({ children }: { children: React.ReactNode }) => {
  cookies();
  return (
    <html lang="en">
      <body className={font.className}>{children}</body>
    </html>
  );
};

export default RootLayout;

// app/page.tsx
export default function Dashboard() {
  return <div>Dashboard</div>;
}


Full project in the zip file.
Image
Image
Avatar
Next Info:
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
Binaries:
  Node: 18.13.0
  npm: 8.1.4
Avatar
Answer
Avatar
European sprat
Ah so it's a windows issue
Avatar
Seems like it's tracked since yesterday
Thank you for your time
Avatar
Norwegian Forest Cat
is there any solution for this? im still facing this issue on windows
Avatar
it's still broken.
using 13.4.7 is the only solution I know of