-
-
Notifications
You must be signed in to change notification settings - Fork 362
-
-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting error while trying to use KY to fetch data in NEXTJS 13 Server APIs 'TypeError: Cannot construct a Request with a Request object that has already been used.' #486
Comments
Have you figured it out ? My assumption is because nextjs is polyfill the native fetch with their own version of fetch. |
The fetch in NextJS behaves differently to the native fetch. |
I can reproduce this, maybe need to raise an issue on next.js side |
I also encountered this issue, I tried with just the native NodeJS fetch (polyfilled by Next) and I don't have the issue with just fetch. |
I also faced this problem. |
Same problem here. I'll probably use just fetch for now. |
I now use ofetch (https://github.com/unjs/ofetch), it has a similar set of features as ky and it works with the app router. |
I am also having troubles getting In my case, it does make request but the json payload is not attached to the request. Using |
Please try awaiting the response before calling Before: return httpClient
.post ("test/test", {
json: {
test: params. test,
}
})
.json() After: const response = await httpClient
.post ("test/test", {
json: {
test: params. test,
}
});
return response.json(); |
I ran into similar issues with the Next.js app folder/server actions/server components or whatnot. The solution was quite simple for me and it was upgrading to Node 18+. Apparently, Node pre-18 is not supporting native fetch and I do suppose Next.js has troubles with that. Unfortunately, the fact Ky is node 18+ is at the bottom of the docs, so it took a while to find out. |
I just tried, not working |
Hi Guys,
Config:
I'm trying to use KY to retrieve data from backend services. I'm using KY in the NextJS APIs folder to call down-stream services. However, I am receiving the error mentioned below.
HTTP Client Code Ref:
The structure I'm attempting to set up for the http client is seen above. So I'm trying to create an HTTP client and passing it to the service as arguments to the function, and then with that client service is calling downstream APIs to get data.
Service Code Ref:
It works perfectly with NextJS 12, however when I try to implement it with NextJS 13, I get this problem. Could someone please assist me with this?
Thanks
The text was updated successfully, but these errors were encountered: