Next.js Discord

Discord Forum

Error: Invariant: AsyncLocalStorage accessed in runtime where it is not available

Unanswered
Alligator mississippiensis posted this in #help-forum
Open in Discord
Alligator mississippiensisOP
Hey, I'm using nextjs with custom express server, babel and webpack, apollo graphql client, emotionjs. I'm using the pages directory and not the app directory.

I just need to point to right direction as I'm getting an error when starting the app with version 16.0.3:

Error: Invariant: AsyncLocalStorage accessed in runtime where it is not available


The error started appearing in version 15.5.6 when I was trying to access and call apollo in the req object and handle some logic before redirecting users based of the data I'd get in an express middleware when accessing the route that would be the exact same as the route in pages directory.

The app would start normally, but would crash on some conditions from the middleware on this particular error.

In version 16.0.3. the app just won even start and ends with the error.

Is there any notable change in the Nextjs project that would forbid us from doing so that would cause the error? Or handling the imports, compilation, ... Idk im just lost at this point.

With version 15.3.2 of nextjs everything works just fine.

1 Reply