> Error: Invariant: headers() expects to have requestAsyncStorage, none available
Hi, I use trpc v1045.1 in next 14.1 app router. I call it server side and have the following.
It is working on a static route but on a dynamic route
/edit/[slug]
I get the following error (coming from the headers() in createServerApi):
Error: Invariant: headers() expects to have requestAsyncStorage, none availableAny idea how I could solve this?
4 Replies
You need to call createServerApi from within your server component, you are currently calling headers() outside of Next
Oh ok, but why is it working for static route? So no way to have a single function to call in the server ? I have to do :
But would like to only have to do :
const post = await api.posts.getPostById(slug);
You can do that in v11 not in v10. In v10 you’ll have to use this pattern, or you’d have to use a proxy probably
Thanks a lot for the clarification and for helping @BeBoRE , really appreciate!