Benfa
Benfa3mo ago

TRPCError: Missing content-type header

Hi, i haven't been using trpc in a while, i'm trying o setup TRPC on a fastify backend and react frontend. I followed the example from the doc but when react tries to fetchs some data i get the following error:
Error in tRPC handler on path 'undefined': TRPCError: Missing content-type header
at getContentTypeHandler (/Users/andreabenfatti/Dev/tmp/fastify-test/node_modules/.pnpm/@trpc+server@11.0.0_typescript@5.8.3/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/contentType.js:221:11)
at Object.getRequestInfo (/Users/andreabenfatti/Dev/tmp/fastify-test/node_modules/.pnpm/@trpc+server@11.0.0_typescript@5.8.3/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/contentType.js:227:21)
......
test/node_modules/.pnpm/fastify@5.3.3/node_modules/fastify/lib/handleRequest.js:119:5) {
cause: undefined,
code: 'UNSUPPORTED_MEDIA_TYPE'
}
Error in tRPC handler on path 'undefined': TRPCError: Missing content-type header
at getContentTypeHandler (/Users/andreabenfatti/Dev/tmp/fastify-test/node_modules/.pnpm/@trpc+server@11.0.0_typescript@5.8.3/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/contentType.js:221:11)
at Object.getRequestInfo (/Users/andreabenfatti/Dev/tmp/fastify-test/node_modules/.pnpm/@trpc+server@11.0.0_typescript@5.8.3/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/contentType.js:227:21)
......
test/node_modules/.pnpm/fastify@5.3.3/node_modules/fastify/lib/handleRequest.js:119:5) {
cause: undefined,
code: 'UNSUPPORTED_MEDIA_TYPE'
}
Checking at the borwser network i see it is requesting the url: http://localhost:3000/trpc/test?batch=1&input=%7B%7D and i if i go to that URL i get back the data correctly. Any idea of what could be the problem?
Solution:
Right after asking the question I found the problem. It something that has to do with CORS. I solved it using vite proxy to forward the request to the server and now everything works as expected
Jump to solution
3 Replies
Nick
Nick3mo ago
Are you definitely using the same version of both client and server? V10 client may not work Also ensure fastify isn’t set up to filter out any headers somehow, like middleware’s ahead of tRPC in the chain (I know with express there are some middlewares that cause problems for instance)
Benfa
BenfaOP3mo ago
Thanks for the fast response. I'm using the same version on both client and server.
Solution
Benfa
Benfa3mo ago
Right after asking the question I found the problem. It something that has to do with CORS. I solved it using vite proxy to forward the request to the server and now everything works as expected

Did you find this page helpful?