DTK0020: RPC Function Not Registered
Package:
@vitejs/devtools
Message
RPC function "
{name}" is not registered
Cause
The RpcFunctionsHost.invokeLocal() method was called with a function name that has not been registered in the RPC definitions map. This method is used to call server-side RPC functions directly without going through the WebSocket transport. The function must have been registered via defineRpcFunction and collected by the RPC host before it can be invoked locally.
Example
ts
export default defineDevToolsPlugin({
name: 'my-plugin',
setup(context) {
// Attempting to invoke a function that hasn't been registered throws DTK0020
await context.rpc.invokeLocal('my-plugin:unregistered-fn')
},
})Fix
Ensure the RPC function is registered before calling invokeLocal(). The function must be defined using defineRpcFunction and set up within a plugin that has already been initialized.
ts
import { defineRpcFunction } from '@vitejs/devtools-kit'
// Define the function
export const myFunction = defineRpcFunction({
name: 'my-plugin:my-function',
type: 'query',
setup: context => ({
handler: () => {
return { result: 'hello' }
},
}),
})
// Later, invoke it locally (after it has been registered)
const result = await context.rpc.invokeLocal('my-plugin:my-function')Source
packages/core/src/node/host-functions.ts