ToP
ToP
TtRPC
Created by ToP on 3/9/2025 in #❓-help
Cannot set headers after they are sent to the client
Thats it! I have been using unstable_httpBatchStreamLink so I switched to httpBatchLink and it fixed the issue. Thank you mate, you just saved my ass.
7 replies
TtRPC
Created by ToP on 3/9/2025 in #❓-help
Cannot set headers after they are sent to the client
I tried to narrow it down. It seems to be problem with createContext. Even if i change it to this very simple implementation, it returns same error.
export const createContext = async ({ req, res }: CreateHTTPContextOptions) => {
return {
setAccessTokenCookie: (token: string | null) => {
res.appendHeader(
'Set-Cookie',
`accessToken=${token}; HttpOnly; SameSite=Strict; Path=/; Domain=localhost; Max-Age=900`
)
},
}
}
export const createContext = async ({ req, res }: CreateHTTPContextOptions) => {
return {
setAccessTokenCookie: (token: string | null) => {
res.appendHeader(
'Set-Cookie',
`accessToken=${token}; HttpOnly; SameSite=Strict; Path=/; Domain=localhost; Max-Age=900`
)
},
}
}
It seem like, that I can set cookies in createContext like this:
export const createContext = async ({ req, res }: CreateHTTPContextOptions) => {
res.appendHeader(
'Set-Cookie',
`accessToken=whatever; HttpOnly; SameSite=Strict; Path=/; Domain=localhost; Max-Age=900`
)
return {}
}
export const createContext = async ({ req, res }: CreateHTTPContextOptions) => {
res.appendHeader(
'Set-Cookie',
`accessToken=whatever; HttpOnly; SameSite=Strict; Path=/; Domain=localhost; Max-Age=900`
)
return {}
}
But if I return method from createContext (first example), or even if I return res and then call res.appendHeader(...) in my route, it always return this error 🤔 Seems like res in mutable only in createContext but not in routes (authRouter.login etc.)
7 replies
TtRPC
Created by mh15 on 12/4/2023 in #❓-help
`The property 'query' in your router collides with a built-in method`
Yeah. Maybe it might be good idea to have working example of tsconfig in docs? And maybe even collection of keys you cant use in your tsconfig? It might help some people in future.
19 replies
TtRPC
Created by mh15 on 12/4/2023 in #❓-help
`The property 'query' in your router collides with a built-in method`
I have solution. In my case, it was caused by defining type of router, instead of letting it be infered. So instead of: const router: ReturnType<typeof router> = router({...}) I did this: const router = router({...}) The reason why I added type to router in first place was because, it was giving me this error The inferred type of 'router' references an inaccessible 'this' type. A type annotation is necessary. But that was caused by tsconfig.json I needed to remove "declaration": true Now everything works perfectly
19 replies
TtRPC
Created by mh15 on 12/4/2023 in #❓-help
`The property 'query' in your router collides with a built-in method`
Not yet. I will prep demo and if we manage to fix this, we can maybe even use it in examples as turborepo with trpc standalone and sveltekit
19 replies
TtRPC
Created by mh15 on 12/4/2023 in #❓-help
`The property 'query' in your router collides with a built-in method`
I have exactly same issue. I tried to narrow it down, by reverting to most basic setup of trpc from Quickstart. Only difference is that I am using turborepo. At first I didnt even had types (everything was any), when i imported from trpc package from turborepo to client app. But then i used Subpath imports and now vscode shows correct types. But then, when i create tRPC client it has this string type instead of something useful: "The property 'query' in your router collides with a built-in method, rename this router or procedure on your backend." | "The property 'mutation' in your router collides with a built-in method, rename this router or procedure on your backend." | ... 5 more ... | "The property 'runtime' in your router collides with a built-in method, rename this router or procedure on your backend." Only thing that helped was moving server to same package as the app. Effectively canceling monorepo 😀 I think that problem is that in turborepo, I cant really import AppRouter type with relative path, because it is import between turborepo packages, and they do some magic with paths which breaks trpc types probably :/ It is only type/intellisense issue, everything else works. But I would say that typesafety and intellisense is kinda main reason why people love tRPC. I dont expect that anybody would be able to help me with this, but if somebody could maybe explain what this error means and why it can occur, that would help me greatly
19 replies