-
Notifications
You must be signed in to change notification settings - Fork 202
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
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client #1
Comments
I am getting this error too. I was able to fix it by adding `typeof window === 'undefined' to the conditional expression with writeHead. Now it looks like this:
I am honestly now positive why you need this though. |
Instead of strict equality (===) operator use Object,is() and le me know! |
I had a similar issue, but I was trying to do all with ts. When I convert all to js everything was working as should be |
Can anyone explain what exactly is happening here? |
Having the same error. However, if I log params as the first line of getServerSideProps, the function works. Some kind of timing issue where params is not ready when fetch tries to call it, maybe? export async function getServerSideProps({params, req, res}) {
console.log(params)
const response = await fetch(`http://localhost:3000/api/note/${params.id}`)
if (!response.ok) {
res.writeHead(302, { Location: '/notes' })
res.end()
return {props: {}}
}
const {data} = await response.json()
if (data) {
return {
props: {note: data}
}
}
}``` |
try this it worked for me if (!response.ok) { const { data } = await response.json(); if (data) { |
Hi Scott @Hendrixer
When I fetch one note in /pages/notes/[id].js the app crashes with the follwoing error:
This is my code for /pages/notes/[id].js:
NOTE: only difference I have from your repo is named exports, my API is at API/notes & my components and data are in root.
A console.log(response) shows:
Steps to trigger the error - follow this path:
Steps to avoid error:
But as soon as you click Notes in Nav bar then you're in trouble again.
Looks like new IDs are generated and somehow headers cannot be updated anymore.
The text was updated successfully, but these errors were encountered: