#TypeError: fetch failed in code, even though it runs properly on the server

3 messages · Page 1 of 1 (latest)

harsh plank
#

I am trying make a GET request using fetch api, and I get a TypeError. I am using TS.
Error:

Error: fetch failed

Call Stack
Object.fetch
node:internal/deps/undici/undici (11118:11)
process.processTicksAndRejections
node:internal/process/task_queues (95:5)```

function in utils/index.ts
```ts
export async function fetchShowData() {
  const headers = {
    Authorization: "Bearer KEY",
  };

  const url = "https://animeschedule.net/api/v3/timetables";
  const response = await fetch(url, { headers: headers });
  const calendarData = await response.json();
  return calendarData;
}```

and my page.tsx
```ts
import { fetchShowData } from "@/utils";

export default async function Home() {
  const allAnime = await fetchShowData();
  console.log(allAnime);
  return (
    <div>
      <main>test</main>
    </div>
  );
}```
calm saddleBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

      🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in <id:customize>

      ✅ You can mark a message as the answer for your post with `Right click -> Apps -> Mark Solution`
      (if you don't see the option, try refreshing Discord with Ctrl + R)
harsh plank
#

I think I made a typo in the title, what I meant was, it runs properly on the console