Skip to content

Installation

  • Node.js >= 20
  • Electron >= 22
  • tRPC v11 (@trpc/server and @trpc/client)
Terminal window
npm install electron-messageport-trpc @trpc/server@^11 @trpc/client@^11

Import the API from the package path that matches the Electron process where the code runs:

| Import path | Process | Purpose | |---|---|---| | electron-messageport-trpc/main | Main | Port broker and request handler | | electron-messageport-trpc/preload | Preload | Expose port receiver to renderer | | electron-messageport-trpc/renderer | Renderer | tRPC link and port getter | | electron-messageport-trpc/utility | Utility | Attach a tRPC handler to parentPort in a utility process |

The package includes TypeScript declarations. For tRPC inference, export the router type from the process that defines the router and import that type where you create a client:

main/router.ts
import { initTRPC } from '@trpc/server';
const t = initTRPC.create();
export const appRouter = t.router({
// ... your procedures
});
export type AppRouter = typeof appRouter;

Next: Quick Start