tRPCttRPC
Powered by
BenfaB
tRPC•8mo ago•
7 replies
Benfa

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
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Missing content type header for mutations leads to 405
pupoPpupo / ❓-help
2y ago
v11 `Invalid Content-Type header`
jlarmstJjlarmst / ❓-help
2y ago
Customizing the TRPCError type
Emmie PäivärintaEEmmie Päivärinta / ❓-help
6mo ago
TRPCError that has TRPCError as cause
TkDodo 🔮TTkDodo 🔮 / ❓-help
3y ago