Reputation: 27
error - Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client at new NodeError (internal/errors.js:322:7) at ServerResponse.setHeader (_http_outgoing.js:561:11) at NodeNextResponse.setHeader (E:\EndGame\FoodMart-client-side\node_modules\next\dist\server\base-http.js:101:19) at DevServer.renderError (E:\EndGame\FoodMart-client-side\node_modules\next\dist\server\base-server.js:1094:17) at DevServer.renderError (E:\EndGame\FoodMart-client-side\node_modules\next\dist\server\next-server.js:414:22) at DevServer.run (E:\EndGame\FoodMart-client-side\node_modules\next\dist\server\dev\next-dev-server.js:451:35) at processTicksAndRejections (internal/process/task_queues.js:95:5) at async DevServer.handleRequest (E:\EndGame\FoodMart-client-side\node_modules\next\dist\server\base-server.js:305:20) { code: 'ERR_HTTP_HEADERS_SENT' }
i can not understand from where the erron come in terminal but live site is okk.
Upvotes: 1
Views: 4883
Reputation: 3730
In your Next.js application, check your pages/api/preview.js file. There is some code there that needs to be correct before the redirect will work
export default function handler(req, res) {
res.setPreviewData({})
res.redirect(req.query.redirect)
}
if you have something like the following your code won't work
res.end('Preview mode enabled')
Upvotes: 1
Reputation: 111
I think you are using express. Somewhere in the code, you send the response after another response is sent. Make sure that you return the function after you call a res.send. All your res.send should have a return: return rsp.send({});
Upvotes: 0