ERR_INSPECTOR_ALREADY_ACTIVATED
Node.jsERRORCriticalInspectorHIGH confidence

Inspector is already activated

Production Risk

Low — the inspector should not be opened in production code.

What this means

Thrown when inspector.open() is called but the inspector is already active. The Node.js inspector can only be opened once per process; calling open() again while it is already listening is not permitted.

Why it happens
  1. 1Calling inspector.open() more than once without calling inspector.close() first
  2. 2Multiple modules or plugins both trying to open the inspector
How to reproduce

Triggered when inspector.open() is called on an already-active inspector session.

trigger — this will error
trigger — this will error
const inspector = require('inspector');
inspector.open(9229);
inspector.open(9229); // already active — throws

expected output

Error [ERR_INSPECTOR_ALREADY_ACTIVATED]: Inspector is already activated

Fix

Check if the inspector is open before calling open()

WHEN When multiple code paths may try to open the inspector

Check if the inspector is open before calling open()
const inspector = require('inspector');
if (!inspector.url()) { // url() returns undefined if not open
  inspector.open(9229, 'localhost', false);
}

Why this works

inspector.url() returns the WebSocket URL if active; checking it prevents duplicate opens.

Code examples
Triggerjs
const inspector = require('inspector');
inspector.open(9229);
inspector.open(9229); // already active — throws  // this triggers ERR_INSPECTOR_ALREADY_ACTIVATED
Handle in try/catchjs
try {
  // operation that may throw ERR_INSPECTOR_ALREADY_ACTIVATED
  riskyOperation()
} catch (err) {
  if (err.code === 'ERR_INSPECTOR_ALREADY_ACTIVATED') {
    console.error('ERR_INSPECTOR_ALREADY_ACTIVATED:', err.message)
  } else {
    throw err
  }
}
Defensive pattern to avoid itjs
// Validate inputs before calling the operation
function safe_err_inspector_already_activated(...args) {
  // validate args here
  return performOperation(...args)
}
What not to do

Call inspector.open() unconditionally multiple times

The inspector is a singleton per process; re-opening without closing throws.

Sources
Official documentation ↗

Node.js Error Codes Documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Node.js errors