DTK0001: RPC Function Already Registered
Package:
@vitejs/devtools-rpc
Message
RPC function "
{name}" is already registered
Cause
This error is thrown by RpcFunctionsCollectorBase.register() when you attempt to register an RPC function with a name that already exists in the collector. Each function name must be unique within a collector instance unless you explicitly opt into overwriting.
Example
ts
import { defineRpcFunction } from '@vitejs/devtools-kit'
const getVersion = defineRpcFunction({
name: 'my-plugin:get-version',
type: 'static',
handler: () => '1.0.0',
})
const getVersionAlt = defineRpcFunction({
name: 'my-plugin:get-version', // same name as above
type: 'static',
handler: () => '2.0.0',
})
// First registration succeeds
collector.register(getVersion)
// Second registration throws DTK0001
collector.register(getVersionAlt)Fix
Either use a unique name for each function, or pass force: true to overwrite the existing registration:
ts
// Option 1: Use a unique name
const getVersionAlt = defineRpcFunction({
name: 'my-plugin:get-version-alt',
type: 'static',
handler: () => '2.0.0',
})
collector.register(getVersionAlt)
// Option 2: Force overwrite
collector.register(getVersionAlt, true)Source
packages/rpc/src/collector.ts