You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
docs: Add an example of a minimal integration with Next.js app router #6586
Right now there is only a minimal integration of trpc with Next.js pages router. It would be very helpful to have one with Next.js app router.
I find it very hard to understand how to do. There are many pages to go through in the doc: the Next.js pages router example, the doc to adapt it to app router, the doc to adapt it to directly using Tanstack Query, etc.
Link to related docs
No response
Additional information
No response
👨👧👦 Contributing
🙋♂️ Yes, I'd be down to file a PR implementing the suggested changes!
Yeah, I'm having a hard time implementing this with NextJS 15 as well, I've successfully done so but I'm getting 404 errors when I'm trying to send requests, not sure how the adapter would work with route.ts file since that's what we're following now with Next 15.
○ Compiling /api/trpc/[trpc] ...
✓ Compiled /api/trpc/[trpc] in 548ms
⨯ Detected default export in '[project]/src/app/api/trpc/[trpc]/route.ts'. Export a named export for each HTTP method instead.
⨯ No HTTP methods exported in '[project]/src/app/api/trpc/[trpc]/route.ts'. Export a named export for each HTTP method.
⨯ Detected default export in '[project]/src/app/api/trpc/[trpc]/route.ts'. Export a named export for each HTTP method instead.
⨯ No HTTP methods exported in '[project]/src/app/api/trpc/[trpc]/route.ts'. Export a named export for each HTTP method.
EDIT:
I tried:
import{appRouter}from'@/server/trpc/router';import*astrpcNextfrom'@trpc/server/adapters/next';// export API handler// @link https://trpc.io/docs/v11/server/adaptersexportconstPOST=trpcNext.createNextApiHandler({router: appRouter,createContext: ()=>({})});
and I was able to hit the endpoint but I get TypeError: res.end is not a function
This issue has been locked because we are very unlikely to see comments on closed issues. If you are running into a similar issue, please create a new issue. Thank you.
Activity
juliusmarminge commentedon Mar 9, 2025
https://trpc.io/docs/client/tanstack-react-query/server-components
lcswillems commentedon Mar 9, 2025
@juliusmarminge It is not complete. For example it doesn't explain the part with API handlers, and so I need to go elsewhere.
Also, having an code example in https://github.com/trpc/trpc/tree/next/examples would help a lot too.
aprilmintacpineda commentedon Mar 24, 2025
Yeah, I'm having a hard time implementing this with NextJS 15 as well, I've successfully done so but I'm getting 404 errors when I'm trying to send requests, not sure how the adapter would work with
route.tsfile since that's what we're following now with Next 15.EDIT:
I tried:
and I was able to hit the endpoint but I get
TypeError: res.end is not a functionEDIT:
Found this https://github.com/trpc/examples-next-app-dir/blob/main/src/app/api/trpc/%5Btrpc%5D/route.ts
AnassAb commentedon May 3, 2025
I'm surprised that there are no docs for NextJS App Router integration, although they are "a match made in heaven" their words not mine.
KATT commentedon Nov 3, 2026
🤖
examples/next-minimal-starteris now a minimal App Router example with@trpc/tanstack-react-query: a route handler, a server component that prefetches and hydrates a query, and a subscription. It landed in #7844: https://github.com/trpc/trpc/tree/main/examples/next-minimal-starter. Closing.github-actions commentedon Nov 4, 2026
This issue has been locked because we are very unlikely to see comments on closed issues. If you are running into a similar issue, please create a new issue. Thank you.