tRPC

T

tRPC

Move Fast & Break Nothing. End-to-end typesafe APIs made easy.

Join

Use TRPCClientError.cause in frontend

Hi all, My TRPC route can sometimes fail. Say the error is CartValidationError In the frontend, I want to be able to do: ```...

Inconsistent types for mutation return type

I have a signIn mutation that returns: ``` { accessToken: string;...
No description

Possible to build this custom hook?

Hello! I'm facing a challenge and hope to get some guidance here. I'm building an admin dashboard for creating and editing data - let's just say it's product data. I built a product management form that I want to use for both creating and editing a product, because the fields are the same. ...

Hydration error when using useQuery instead of useSuspenseQuery when prefetching

I have a page ```tsx export const PostsPage = async ({ params }: PostsPageProps) => { trpc.posts.getAll.prefetch({ userId: user.id });...

tRPC 404 in Next.js API Routes

I'm trying to upgrade my Next.js version to 15 and still use tRPC with API route. I'm getting 404 for all trpc api routes. Is anyone else facing the same issue? All the other api routes are working fine. app/api/trpc/[trpc]/route.ts ```ts import { fetchRequestHandler } from "@trpc/server/adapters/fetch";...

Best Monorepo Pattern for Sharing tRPC Logic Across Apps

Hey tRPC community! I'm working on a monorepo with a standalone tRPC server, a React Native app, and a Next.js app. Both frontend apps share a lot of common logic, particularly custom React hooks that wrap tRPC calls. Currently, my proposed solution is to create shared hooks that require a React context providing the tRPC client. This approach allows each app to instantiate its own tRPC client (both based on the same AppRouter) while maintaining shared logic....

tRPC CORS error

Hello, I have tRPC setup with express.js and next.js (as the client) within a turborepo and tRPC as a shared package. What am I doing wrong to get a cors error. Any help would be appreciated.
No description

Prefetch using Next App router not working with useQuery but works with useSuspenseQuery

1. I'm not using the next adapter 2. I'm using the Next App Router 3. Using useSuspenseQuery works as expected, the query doesnt run onMount because it was prefetched, but it always runs using useQuery My server side page.tsx:...

tRPC Client Bundling `node_modules`

Hey team, I've been having an issue recently where tRPC seems to be bundling a .pnpm and node_modules in @trpc/client. This is causing a lot of errors as I'm not using pnpm: <project>/node_modules/@trpc/client/dist/TRPCClientError.mjs ```js import { _ as _define_property } from './node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.mjs';...

onSuccess and onError in one time

Hi! I have onError and onSuccess execute in one time

Context parameters in server side calls

Hello, I using trpc 11.0.0-rc.633 and Next.js 15.0.3 and have the following questions: 1. when a createContext() function is defined with the FetchCreateContextFnOptions parameter signature, how do you fill that information out when using server side api calls, for example via createCaller? The example in the docs is inaccurate in that it defines a createContext function to require some parameters:
export const createContext = async (opts: CreateNextContextOptions) => { ... }
export const createContext = async (opts: CreateNextContextOptions) => { ... }
...

Trigger.dev

Is anyone here running tRPC procedures on Trigger.dev v3? I used tRPC just fine on V2, but since V3 code runs in their servers, it's throwing fetch failed errors.

Calling mutation with formData causes error: iterator method is not callable

uploadMutation.mutate(formData) causes error
TRPCClientError: iterator method is not callable
TRPCClientError: iterator method is not callable
If I call it without the formData, it works...

Does tRPC require next?

I'm updating my repo from @trpc/server@11.0.0-rc.553 to @trpc/server@11.0.0-rc.638 but my lockfile gets massive because pnpm installs Next.js See https://github.com/bnussman/beep/pull/111/files#diff-32824c984905bb02bc7ffcef96a77addd1f1602cff71a11fbbfdd7f53ee026bbR12006 Am I doing something wrong or has something changed on the @trpc/server side? ...

Do I need a server to use tRPC?

Since we use RQ at work for our product - I thought might as well bring tRPC into it since it couples things very well. We dont do anything serverless on the frontend, so curious if I need to install an adapter to Vite and spin up a server?

Can't get type inference from createTRPCNext instance

Hi everyone, I have separate FE and BE using tRPC to communicate, in a monorepo environment. The FE app is a simple Next.js app, the BE is tRPC with Express. I'm using Bun as the runtime. I'm exporting AppRouter from the BE as per the instructions, and importing the type in the FE and passing it as a type argument to createTRPCNext. When inspecting createTRPCNext in the FE, I can see the type has resolved and the procedures are in there....

Not able to seed react query cache

I was reading this blog post from the react-query dev: https://tkdodo.eu/blog/seeding-the-query-cache#seeding-details-from-lists And trying to follow the "push approach" here for seeding the react query cache but adapting it to @trpc/react-query Here is the code I wrote. ```ts...

What is wrong with my subscription setup?

Hi, I'm new to trpc and while playing with subscriptions for some reason I can't make it work. In this gist (https://gist.github.com/odiel/f4d3d09650fd1598ea29f6750e76841a) I have the server and client setup. I'm using the latest Deno version and "@trpc/server": "npm:@trpc/server@^11.0.0-rc.638", "@trpc/client": "npm:@trpc/client@^11.0.0-rc.638",. Once running the client it stays in, and I don't get to see any of the events emitted on the backend reaching the client. What am I doing wrong? ``` << subscription #1 example { input: undefined,...

Make server side tRPC calls on an external tRPC server ?

Hello, there is a very valid discussion on github that has still not been discussed : https://github.com/trpc/trpc/discussions/5989
Next