Next.js Discord

Discord Forum

Next 14.2.3 - API Route strange behavior on dev server

Unanswered
Jamison posted this in #help-forum
Open in Discord
Hello 🙂

On the version in my title I have been running intro weird beavior with API routes on the development server.

In one of my components I'm doing some client side fetching via a useEffect. When I run it on the development server I get errors on my server saying Response.Json is not a function. Then if I navigate to the actual route in my browser, it throws the same error.

However, if I start the development server, then go to the route in my browser first, before I do client side fetching; it returns the JSON fine and then the client side fetching will work.

This does not happen when I build the project and then run it.

What I think is happening is the api route is not being compiled properly when I fetch from the client somehow? Because if I force it to compile (by navigating there myself before client side fetching in the browser, or hitting it with CURL) then it works (only if I haven't tried to client side fetch).

It's not really breaking my app as it works in production build but its kind of annoying for development

I'm wondering if anyone's run into ths and knows what to do? Or maybe I'm doing something wrong.

Thanks

4 Replies

Yep I might do so, only popped up recently