Installation
Prerequisites
Section titled “Prerequisites”- Node.js >= 20
- Electron >= 22
- tRPC v11 (
@trpc/serverand@trpc/client)
Install the Package
Section titled “Install the Package”npm install electron-messageport-trpc @trpc/server@^11 @trpc/client@^11pnpm add electron-messageport-trpc @trpc/server@^11 @trpc/client@^11yarn add electron-messageport-trpc @trpc/server@^11 @trpc/client@^11Import Paths
Section titled “Import Paths”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 |
Router Type Export
Section titled “Router Type Export”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:
import { initTRPC } from '@trpc/server';
const t = initTRPC.create();export const appRouter = t.router({ // ... your procedures});
export type AppRouter = typeof appRouter;Next: Quick Start