DTK0024: Command Already Registered
Package:
@vitejs/devtools
Message
Command "
{id}" is already registered
Cause
The DevToolsCommandsHost.register() method was called with a command id that already exists in the commands map. Each command must have a unique identifier.
Example
ts
export default defineDevToolsPlugin({
name: 'my-plugin',
setup(context) {
context.commands.register({
id: 'my-plugin:reload',
label: 'Reload',
handler: () => { /* ... */ },
})
// Registering with the same id throws DTK0024
context.commands.register({
id: 'my-plugin:reload',
label: 'Reload Again',
handler: () => { /* ... */ },
})
},
})Fix
Use a unique id for each command. If you need to modify an existing command, use the update method on the handle returned by register().
ts
const handle = context.commands.register({
id: 'my-plugin:reload',
label: 'Reload',
handler: () => { /* ... */ },
})
// Update the existing command instead of re-registering
handle.update({ label: 'Reload All' })If you need to replace a command entirely, unregister it first:
ts
handle.unregister()
context.commands.register({
id: 'my-plugin:reload',
label: 'New Reload',
handler: () => { /* ... */ },
})Source
packages/core/src/node/host-commands.ts