Next.js Discord

Discord Forum

type error fetch failed in server component to external api endpoint

Answered
Le Conte's Sparrow posted this in #help-forum
Open in Discord
Le Conte's SparrowOP
https://jsonplaceholder.typicode.com/todos/1 //not work

https://api.agify.io?name=michael // work

https://api.genderize.io?name=luc //work

https://catfact.ninja/fact //work

https://dog.ceo/api/breeds/image/random // not work

https://api.coindesk.com/v1/bpi/currentprice.json // work

https://api.publicapis.org/entries
async function Page() {
const res = await fetch("https://jsonplaceholder.typicode.com/todos/1");
const data = await res.json();
console.log(data);
return (
<div className="p-4">
<pre className="bg-gray-100 p-4 rounded">hello</pre>
</div>
);
}

export default Page;
i found it very weired that as my above code, some api are worked , and some are not work . it did run with npm run dev --experimental-https , but no luck . it all works on client component fetch
Answered by Le Conte's Sparrow
hi thanks for your help , i found that my isp is blocking the cloudflare proxy ,that's why it did not serve the data , it is unstable like i can access sometimes which is why it was worked in client component now it does not worked in client component too.
View full answer

16 Replies

Huh that’s odd
Nothing below it or above it?
Le Conte's SparrowOP
yes
only some api , which is weired to me
in v0 dev , it can run without fetch failed , could be related to my machine or something?
Can you make a script.js file with just this

fetch('https://jsonplaceholder.typicode.com/todos/1')

run it with node script.js and let me know what the terminal says?
Yeah smells like it’s something specific to your machine
Le Conte's SparrowOP
node:internal/deps/undici/undici:13392
Error.captureStackTrace(err);
^

TypeError: fetch failed
at node:internal/deps/undici/undici:13392:13
at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
[cause]: Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:216:20) {
errno: -4077,
code: 'ECONNRESET',
syscall: 'read'
}
}

Node.js v22.11.0
i got this output
Le Conte's SparrowOP
@joulev hi any update?(sorry to mention you)
@joulev thats odd can you go to the typicode.com url in your browser? does the json show up normally there?
Le Conte's SparrowOP
hi thanks for your help , i found that my isp is blocking the cloudflare proxy ,that's why it did not serve the data , it is unstable like i can access sometimes which is why it was worked in client component now it does not worked in client component too.
Answer