-
Notifications
You must be signed in to change notification settings - Fork 28.5k
API resolved without sending a response (another one) #10777
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
Comments
Can't reproduce with import nextConnect from "next-connect";
const handler = nextConnect();
handler.get(async (req, res) => {
return new Promise(resolve => {
res.status(200).json({});
return resolve();
});
});
export default handler; You probably want to share a full reproduction , including the code for |
Thanks for your help @Janpot, but yes, the issue is linked to the middleware, and the fact NextJS is currently not completely compatible with next-connect. There is a pull request for it: here. Hopefully, this will be accepted, and more collaboration will be done with the next-connect library. I am not sure how it is possible to build a product based on NextJS without any middleware, or maybe there is a better alternative? |
The problem happens if you use another handler inside the handler import nextConnect from 'next-connect'
const handler = nextConnect()
handler.use(nextConnect())
handler.get((req, res) => {
res.status(204).end()
})
export default handler it does not print the warning if you use only one handler (and add each middleware separately) another example (with one handler) |
Exactly :) Personally I have stopped using next-connect, and I made my own middlewares. Fewer dependencies, and it's just as easy. That module is cool, but if NextJS doesn't care much about it, I prefer to build solutions avoiding it. |
may you give an example of how you do it? |
Actually, I don't do anything magical. I am just doing basically this: https://nextjs.org/docs/api-routes/api-middlewares. But I have created a little HOC for my API requests, and I basically add everything I need, like the DB, Auth, etc, and make sure those "modules" are singletons. |
Hey, I am the author of |
Thank you so much @hoangvvo! :) I will definitely give it another try. |
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. |
I am not the only one with this issue, but other threads didn't fix my issue. I feel like there might be some issues in the library. Hopefully, it's simply in my code...
Describe the bug
I am using next-connect as well, as I need middlewares (I guess most of us need that library as well). I am always getting this warning:
To Reproduce
I have simplified the code, of course, there are async calls in that function as well, otherwise, I wouldn't use an async function here ;) But this simple example doesn't work either.
I am currently using NextJS 9.2.1 and Next Connect 0.6.0.
The text was updated successfully, but these errors were encountered: