Today | July 14, 2026
web4pps

How I Fixed the “API resolved without sending a response” Error in Next.js

February 27, 2023 10:49 AM

Troubleshoot

PROBLEM

The api throws a warning "API resolved without sending a response" whenever the API is triggered.

Inside the API is a fs.readFile callback function where it checks if a file exist or not. Even though inside the callback there is already a response (res.status(200)) being thrown, the warning still persist.



SOLUTION

The issue occurs is because outside the fs.readFile function there is no response being thrown. Once the API is triggered, it will look for any direct response first which in this case the outside of the fs.readFile function.


To solve this problem, you have to create a new promise function where you put your fs.readFile code and call it inside the checkFile function then throw the API response after the promise resolves. See code below:


This way the API response is directly within checkFile function which solves the warning "API resolved without sending a response". Hope this helps.