-
Notifications
You must be signed in to change notification settings - Fork 27.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False positive report of "API resolved without sending a response" #10439
Comments
This has been fixed in canary, can you try |
This comment has been minimized.
This comment has been minimized.
@iddify please provide code instead of saying "same issue", it's unlikely that you're doing 100% exactly the same as the person that posts an issue. |
This comment has been minimized.
This comment has been minimized.
UPDATE: i wasn't resolving the request, returning a 200 status code after the request finished removed the warning for me, MY BAD! |
@timneutkens Thank you for the quick reply. Unfortunately I don't know exactly how Next analyzes whether or not a route actually returns something, but it could be because of the callback in I also wonder if this couldn't be because of the I will investigate a bit more 👍 |
@gaku-sei it is most likely caused by the export default async function(req: NextApiRequest, res: NextApiResponse) {
return new Promise(resolve => {
switch (req.method) {
case "POST":
case "OPTION": {
try {
const request = http.request( // Node core http module
url,
{
headers: await makeHeaders(req, res),
method: req.method,
},
response => {
response.pipe(res);
resolve()
},
);
request.write(JSON.stringify(req.body));
request.end();
} catch (error) {
Log.error(error); // Can be a simple console.error too
res.status(500).end();
return resolve()
}
}
}
res.status(405).end();
return resolve()
})
} |
@ijjk Thank you very much, that worked perfectly for me! Issue solved 😄 |
I see the same warning with |
@danielhusar Any idea what could be the valid solution for apollo-server-express? Hitting the same issue "API resolved without sending a response for /, this may result in stalled requests.". |
I havent been able to figure it out yet. Im considering to switch to express server to handle all requests. (Instead of just api) |
We're going to add a config option to opt-out of the warning for certain api routes if you're sure they resolve |
I'm still running into this:
|
export default async function token(req, res) {
try {
const { user } = await auth0.getSession(req);
if(!user) {
throw new Error('No User');
}
const result = await fetch(`https://${process.env.domain}/oauth/token`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
grant_type: 'client_credentials',
client_id: process.env.authClientID,
client_secret: process.env.authClientSecret,
audience: `https://${process.env.domain}/api/v2/`,
}),
})
const { access_token, scope, expires_in, token_type } = await result.json()
return { access_token, scope, expires_in, token_type }
} catch (error) {
console.error(error)
return res.status(error.status || 500).end(error.message)
}
} This should solve your case, but you can now disable the warning also: https://nextjs.org/docs/api-routes/api-middlewares // export this from the api route
export const config = {
api: {
externalResolver: true,
},
} |
I'm not sure I understand. I'm getting it with this code which I got from the example for firebase server authentication: pages/api/login.ts: import commonMiddleware from '../../middleware/commonMiddeware';
import { verifyIdToken } from '../../firebase/auth/admin';
const handler = async (req, res) => {
if (!req.body) {
return res.status(400);
}
const { token } = req.body;
try {
const decodedToken = await verifyIdToken(token);
req.session.decodedToken = decodedToken;
req.session.token = token;
return res.status(200).json({ status: true, decodedToken });
} catch (error) {
return res.status(500).json({ error });
}
};
export default commonMiddleware(handler); |
Looks like you're not finishing the request when a body is not set:
Should be:
|
Have the same problem and the above fix isn't working for me. :/ |
I have the same problem. The message just a warning or can it really give you problems? |
I'm having the same problem. Why is this issue closed? Is this a problem from Next server or am I doing something wrong? |
+1 same for me |
I am getting this same warning too however I am getting the data I expect to revieve in the console :/ |
Updated to here's my handler:
When I hit my route I get a json array returned with all the trades.. but I get this in the console:
|
People still running into this issue might want to look closely at: #10439 (comment) and #11380 If you're using an externalResolver (such as Express), nextjs can't detect that the API response has been send. At the bottom of #10439 (comment) @timneutkens explains how you can disable the warning if that is indeed the case. |
I don't think it explains why I would get the warning for |
I had the same issue with the following code: export default async (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'POST') {
handlePost(req, res)
return
}
if (req.method === 'GET') {
handleGet(req, res)
return
}
res.status(405).send('Method not allowed')
} What solved it for me was |
The problem was that (req, res) => ... neeeds to return some default response. E.g. |
Awesome, work perfectly sir😃. |
In order i have done these things with this commit: 1. Fix svg import creating a custom d.ts module and adding includes in tscondig.json 2. Add interfaces and models for the database (added stuff for remote database 3. Added logic and VALIDATORS for uploading notion links 4. fixed a bug described here vercel/next.js#10439 (comment), for sections ts and courses ts, Senza questa promise arrivava il warning: ```API resolved without sending a response for /api/sections, this may result in stalled requests.``` Ossia non sapeva se sta ancora aspettando o no, sta cosa risolve. I made many todos: Like moving the validators to model level
In order i have done these things with this commit: 1. Fix svg import creating a custom d.ts module and adding includes in tscondig.json 2. Add interfaces and models for the database (added stuff for remote database 3. Added logic and VALIDATORS for uploading notion links 4. fixed a bug described here vercel/next.js#10439 (comment), for sections ts and courses ts, Senza questa promise arrivava il warning: ```API resolved without sending a response for /api/sections, this may result in stalled requests.``` Ossia non sapeva se sta ancora aspettando o no, sta cosa risolve. I made many todos: Like moving the validators to model level
* feat: add basic mongo API Created courses and sections api entries with NEXT js. Doesn't have custom filtering or queries integrated with Mongo, should make them by myself. By now i'm just using standard next.js query with mongo params. * refactor(mongo): create main API function, and mongo type created single function that handles native database connection, and the type for our responses * refactor(mongo): delete mongodb package for mongoose added database models, fix for svg typescript import, and database connection * feat: add upload notion links In order i have done these things with this commit: 1. Fix svg import creating a custom d.ts module and adding includes in tscondig.json 2. Add interfaces and models for the database (added stuff for remote database 3. Added logic and VALIDATORS for uploading notion links 4. fixed a bug described here vercel/next.js#10439 (comment), for sections ts and courses ts, Senza questa promise arrivava il warning: ```API resolved without sending a response for /api/sections, this may result in stalled requests.``` Ossia non sapeva se sta ancora aspettando o no, sta cosa risolve. I made many todos: Like moving the validators to model level
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report
Describe the bug
Api endpoint
Next will log the "API resolved without sending a response" warning even though the API endpoint always send a response back.
To Reproduce
Here the code that triggers the warning:
It seems that this endpoint will always send a response back.
Expected behavior
No warning
System information
The text was updated successfully, but these errors were encountered: