LogoRobo.js

Configuration

Server prefix, seed files, API reference, and troubleshooting.

The @robojs/trpc plugin has no configuration options of its own. Its behavior is determined by @robojs/server's prefix setting and the files seeded into your project.

Server prefix

The plugin detects @robojs/server's prefix option at startup and registers the tRPC endpoint at {prefix}/trpc.

config/plugins/robojs/server.mjs
export default {
	prefix: '/api' // default
}
config/plugins/robojs/server.mjs
export default {
	prefix: '/api' // default
}
Server prefixtRPC endpoint
/api (default)/api/trpc
/v1/v1/trpc
'' (empty)/trpc

The client's httpBatchLink URL must match this endpoint. See the client guide for details.

Seed files

When installed via npx robo add @robojs/trpc, three files are seeded into your project:

trpc.tsRegisters router on startup
client.tsReact Query hooks
server.tsRouter + procedures
FilePurpose
src/trpc/server.tsRouter definition with example query and mutation procedures.
src/trpc/client.tsClient setup with both React Query hooks and standalone client.
src/robo/start/trpc.tsStart hook that imports the server file to trigger router registration.

All three files are required for the plugin to function. The start hook is especially critical — without it, the router is never registered and all API calls fail.

Dependencies

Required

PackageVersionPurpose
@robojs/server>= 0.6.0Provides HTTP routing for the tRPC endpoint.
robo.js>= 0.11.0Core framework for lifecycle hooks and plugin system.

Optional

PackageVersionPurpose
react>= 18.0.0Only needed for TRPCProvider and React Query hooks.
zodAnyRecommended for input validation in procedures.

Bundled

These are included with the plugin — no need to install separately:

PackageVersion
@trpc/server11.4.3
@trpc/client11.4.3
@trpc/react-query11.4.3
@tanstack/react-query5.84.1

API reference

Server exports

Exported from @robojs/trpc/server.js:

ExportTypeDescription
initTRPCObjectCustom tRPC initializer. Call .create() to get a tRPC instance with automatic router registration.

Client exports

Exported from @robojs/trpc:

Components

ExportDescription
TRPCProviderReact component that wraps your app with tRPC and React Query providers.

Client creation

ExportDescription
createTRPCClientCreate a standalone tRPC client (no React).
createTRPCReactCreate React Query hooks for tRPC.
createTRPCQueryUtilsCreate query utility helpers for cache management.

Links

ExportDescription
httpBatchLinkBatches multiple requests into one HTTP call.
httpBatchStreamLinkBatch link with streaming support.
httpSubscriptionLinkServer-sent events for subscriptions.
loggerLinkLogs tRPC operations for debugging.
retryLinkRetries failed operations.
splitLinkRoutes operations to different links conditionally.
wsLinkWebSocket transport for subscriptions.
createWSClientCreates a WebSocket client instance.

Error classes

ExportDescription
TRPCErrorThrow typed errors in server procedures with HTTP status codes.
TRPCClientErrorClient-side error class for catching tRPC errors.

Utilities

ExportDescription
getMutationKeyGet React Query mutation key for a tRPC mutation.
getQueryKeyGet React Query query key for a tRPC query.
getUntypedClientGet the underlying untyped client from a typed client.
isTRPCClientErrorType guard to check if an error is a tRPC client error.

Types

ExportDescription
ContextInterface with req: RoboRequest and res: RoboReply available in procedures.

Troubleshooting

"Router is not registered"

This error means the tRPC router was never captured by the plugin. Common causes:

Wrong initTRPC import. Import from @robojs/trpc/server.js, not @trpc/server:

// Correct
import { initTRPC } from '@robojs/trpc/server.js'

// Wrong — bypasses router registration
import { initTRPC } from '@trpc/server'
// Correct
import { initTRPC } from '@robojs/trpc/server.js'

// Wrong — bypasses router registration
import { initTRPC } from '@trpc/server'

Missing start hook. Make sure src/robo/start/trpc.ts exists and imports your server file:

src/robo/start/trpc.ts
export default () => import('../../trpc/server.js')
src/robo/start/trpc.js
export default () => import('../../trpc/server.js')

Router not called. The server file must call t.router() — defining the router is what triggers registration.

404 errors on tRPC calls

The client URL doesn't match the server prefix. If @robojs/server uses a custom prefix, update the httpBatchLink URL:

// If server prefix is '/v1':
httpBatchLink({ url: '/v1/trpc' })

// If server prefix is '' (empty):
httpBatchLink({ url: '/trpc' })
// If server prefix is '/v1':
httpBatchLink({ url: '/v1/trpc' })

// If server prefix is '' (empty):
httpBatchLink({ url: '/trpc' })

TypeScript errors on client

Make sure your server file exports the AppRouter type:

src/trpc/server.ts
export type AppRouter = typeof appRouter
src/trpc/server.js

And the client imports it as a type:

src/trpc/client.ts
import type { AppRouter } from './server'
src/trpc/client.js

Missing @robojs/server

The plugin requires @robojs/server for HTTP routing. Install both together:

npx robo add @robojs/server@next @robojs/trpc@next

Next Steps

On this page