Skip to content

docs: Add an example of a minimal integration with Next.js app router #6586

Closed

Description

@lcswillems

Area of Improvement

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!

Activity

  1. added
    📚 documentation / examples
    on Mar 4, 2025
  2. lcswillems commented on Mar 9, 2025

    @lcswillems
    Author

    @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.

  3. aprilmintacpineda commented on Mar 24, 2025

    @aprilmintacpineda

    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 * as trpcNext from '@trpc/server/adapters/next';
    // export API handler
    // @link https://trpc.io/docs/v11/server/adapters
    export const POST = trpcNext.createNextApiHandler({
      router: appRouter,
      createContext: () => ({})
    });

    and I was able to hit the endpoint but I get TypeError: res.end is not a function

    EDIT:

    Found this https://github.com/trpc/examples-next-app-dir/blob/main/src/app/api/trpc/%5Btrpc%5D/route.ts

  4. AnassAb commented on May 3, 2025

    @AnassAb

    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.

  5. KATT commented on Nov 3, 2026

    @KATT
    Member

    🤖 examples/next-minimal-starter is 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.

  6. github-actions commented on Nov 4, 2026

    @github-actions
    Contributor

    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.

  7. locked as resolved and limited conversation to collaborators on Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    📚 documentation / examples

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions