Skip to content

DTK0018: Terminal Session Already Registered

Package: @vitejs/devtools

Message

Terminal session with id "{id}" already registered

Cause

The DevToolsTerminalHost.register() or DevToolsTerminalHost.startChildProcess() method was called with a session id that is already present in the terminal sessions map. Each terminal session must have a unique identifier. This check runs at the beginning of both register() and startChildProcess() in the DevToolsTerminalHost class.

Example

ts
export default defineDevToolsPlugin({
  name: 'my-plugin',
  setup(context) {
    // First registration succeeds
    context.terminals.register({
      id: 'my-plugin:terminal',
      label: 'My Terminal',
      icon: 'i-carbon-terminal',
    })

    // Second registration with the same id throws DTK0018
    context.terminals.register({
      id: 'my-plugin:terminal', // duplicate id
      label: 'Another Terminal',
      icon: 'i-carbon-terminal',
    })
  },
})

Fix

Use a unique id for each terminal session. If you need to modify an existing session, use context.terminals.update() instead of registering again. If you need to replace a session, call context.terminals.remove() first.

ts
// Option 1: Use a unique id
context.terminals.register({
  id: 'my-plugin:terminal-2',
  label: 'Another Terminal',
  icon: 'i-carbon-terminal',
})

// Option 2: Update the existing session
context.terminals.update({
  id: 'my-plugin:terminal',
  label: 'Updated Label',
})

Source

packages/core/src/node/host-terminals.ts

Released under the MIT License.