Add a route handler that doesn't return a response. For example
export function POST() {}
Run that route handler. For example in the reproduction repository, make a POST request to /api.
Describe the Bug
The following error is thrown:
- error TypeError: Cannot read properties of undefined (reading 'headers')
at /Users/joulev/dev/www/debug/.next/server/chunks/322.js:3106:61
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
It is very unclear and has confused many people in the Next.js Discord server. Of course the error can be fixed by returning a response, but the error is too unclear for developers to know what's wrong.
Expected Behavior
I think it would be good if this either returns a default 200 response (new Response(null) for example) (I prefer this), or throws a clearer error, or both.
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to the code that reproduces this issue or a replay of the bug
https://github.com/joulev/debug/tree/nextjs-route-handler-not-return-error-bug
To Reproduce
Add a route handler that doesn't return a response. For example
Run that route handler. For example in the reproduction repository, make a
POST
request to/api
.Describe the Bug
The following error is thrown:
It is very unclear and has confused many people in the Next.js Discord server. Of course the error can be fixed by returning a response, but the error is too unclear for developers to know what's wrong.
Expected Behavior
I think it would be good if this either returns a default 200 response (
new Response(null)
for example) (I prefer this), or throws a clearer error, or both.Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response