Skip to content

DTK0004: Missing RPC Handler

Package: @vitejs/devtools-rpc

Message

Either handler or setup function must be provided for RPC function "{name}"

Cause

This error is thrown by getRpcHandler() when an RPC function definition provides neither a handler property nor a setup function that returns a handler. It can occur in two situations:

  1. When the collector's proxy tries to resolve a handler for a registered function.
  2. During dumpFunctions() when resolving handlers for pre-computation.

Every RPC function must have a way to produce a handler -- either directly via handler or lazily via setup.

Example

ts
import { defineRpcFunction } from '@vitejs/devtools-kit'

// Missing both handler and setup
const broken = defineRpcFunction({
  name: 'my-plugin:broken',
  type: 'query',
})

collector.register(broken)

// Throws DTK0004 when the handler is resolved
await collector.getHandler('my-plugin:broken')

A setup function that forgets to return a handler also triggers this error:

ts
const alsoMissing = defineRpcFunction({
  name: 'my-plugin:also-missing',
  type: 'query',
  setup: (ctx) => {
    // Forgot to return { handler: ... }
    return {}
  },
})

Fix

Provide a handler directly, or return one from setup:

ts
// Option 1: Direct handler
const getVersion = defineRpcFunction({
  name: 'my-plugin:get-version',
  type: 'static',
  handler: () => '1.0.0',
})

// Option 2: Handler via setup (useful when you need context)
const getConfig = defineRpcFunction({
  name: 'my-plugin:get-config',
  type: 'query',
  setup: ctx => ({
    handler: () => ctx.config,
  }),
})

Source

packages/rpc/src/handler.ts

Released under the MIT License.