Next.js Discord

Discord Forum

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

Answered
Somebody posted this in #help-forum
Open in Discord
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

European sprat
What version of next
latest
13.4.19
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?
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
It works in 13.4.7 too, just tested it out
European sprat
i just tried a new create-next-app at it works
broken in 13.4.17 and 13.4.19
European sprat
all i did was add the runtime export and logged out the cookies and i can see them
tested with prod build too
I'll try to reproduce it with a smaller code base
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.
Next Info:
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
Binaries:
  Node: 18.13.0
  npm: 8.1.4
Answer
European sprat
Ah so it's a windows issue
Seems like it's tracked since yesterday
Thank you for your time
Norwegian Forest Cat
is there any solution for this? im still facing this issue on windows
it's still broken.
using 13.4.7 is the only solution I know of