Next.js Discord

Discord Forum

TypeError: Failed to fetch 🤯

Unanswered
Lazyllama posted this in #help-forum
Open in Discord
I'm genuinely about to lose it. localhost:3000/characters is working with all data showing. When I'm on localhost:3000/ and use the href in the navbar it throws this stupid error for every person then gives me error.js after redirecting me to localhost:3000/characters. This is my first time using NextJS, actually react at all so excuse my spaghetti code and if you want to you can give me tips. Also tag me if something is unclear

https://gist.github.com/Lazylllama/699e31685bc895c1d165bb0e2c4c5749
https://gist.github.com/Lazylllama/0c88df209641b202812db68b0203cde3

Using template: https://github.com/vercel/nextjs-postgres-nextauth-tailwindcss-template

16 Replies

Thrianta
The first file you linked should not be a client component. The way I can tell is by it not using/importing any client side logic (state management, useEffect/watchers). Also, since you are doing a "secret" api fetch, it should be a server component so that the api key is never exposed to the client. Also, client components can't be async. I.e. every component in a "use client" file must not be async.
Thrianta
Cool. As long as you removed "use client" from steam-data.tsx I can't complain
Removed "use client"
Still the same error
Thrianta
And you say this getSteamData works in other places? Why not log out the response when !reponse.ok to get some more information? If you provide me with a valid steam64id I could try to fetch it myself
When i manually go to localhost:3000/characters by entering the URL everything works
But when I use the navbar, it doesn't redirect and throws the error on the page I'm on.
@Lazyllama When i manually go to `localhost:3000/characters` by entering the URL everything works
Gonna test using router
Thrianta
Also try replacing any <a/> tags with import Link from "next/link" component. It might make a difference
nav-item.tsx