denoland/deno · error · Error
ERR_INSPECTOR_ALREADY_ACTIVATED
ERR_INSPECTOR_ALREADY_ACTIVATED
Error message
Inspector is already activated. Close it with inspector.close() before activating it again.
What it means
inspector.open([port[, host[, wait]]]) activates the inspector for the process. If an inspector is already active — the process was started with --inspect/--inspect-brk, or inspector.open() was called earlier and not closed — op_inspector_enabled() returns true and open() throws ERR_INSPECTOR_ALREADY_ACTIVATED, with the message telling you to close it via inspector.close() first.
Source
Thrown at ext/node/polyfills/inspector.js:228
}
op_inspector_disconnect(this.#connection);
this.#connection = null;
for (
const { 1: callback } of new SafeMapIterator(this.#messageCallbacks)
) {
lazyProcess().default.nextTick(callback, new ERR_INSPECTOR_CLOSED());
}
this.#messageCallbacks.clear();
this.#nextId = 1;
this.#pendingMessages.length = 0;
this.#drainScheduled = false;
this.#isDraining = false;
}
}
function open(port, host, wait) {
if (op_inspector_enabled()) {
throw new ERR_INSPECTOR_ALREADY_ACTIVATED();
}
// inspectorOpen() currently does not typecheck its arguments and adding
// such checks would be a potentially breaking change. However, the native
// open() function requires the port to fit into a 16-bit unsigned integer,
// causing an integer overflow otherwise, so we at least need to prevent that.
if (isUint32(port)) {
validateInt32(port, "port", 0, 65535);
} else {
// equiv of handling args[0]->IsUint32()
port = undefined;
}
if (typeof host !== "string") {
// equiv of handling args[1]->IsString()
host = undefined;
}
if (host && !isLoopback(host)) {
lazyProcess().default.emitWarning(View on GitHub (pinned to 9ad36f7a2c)
Solutions
- Guard the call: only open when inspector.url() === undefined (url() returns undefined when no inspector is active).
- Call inspector.close() before inspector.open() when re-activating after a previous open.
- Drop the --inspect/--inspect-brk flag from the launch command if the program opens the inspector itself.
Example fix
// before - launched with: deno run --inspect app.ts
inspector.open(9229, '127.0.0.1'); // ERR_INSPECTOR_ALREADY_ACTIVATED
// after
if (inspector.url() === undefined) {
inspector.open(9229, '127.0.0.1');
} Defensive patterns
Strategy: validation
Validate before calling
import inspector from 'node:inspector';
function openInspector(port, host) {
if (inspector.url() !== undefined) return inspector.url(); // already active
inspector.open(port, host);
return inspector.url();
} Type guard
import inspector from 'node:inspector';
function inspectorIsActive() {
return inspector.url() !== undefined;
} Try / catch
try {
inspector.open(9229, '127.0.0.1');
} catch (e) {
if (e.code === 'ERR_INSPECTOR_ALREADY_ACTIVATED') {
// inspector already running (e.g. via --inspect); continue with inspector.url()
} else throw e;
} Prevention
- Never combine --inspect in the launch command with inspector.open() in code.
- Make programmatic open() idempotent: check inspector.url() first, or close() before open() in reload paths.
When it happens
Trigger: Running `deno run --inspect app.ts` (or equivalent flags) where app.ts itself calls inspector.open(); calling inspector.open() twice, e.g. at startup and again on config reload/SIGHUP.
Common situations: Dev scripts that open the inspector programmatically while the launch command already has --inspect; watch/reload loops re-running init code; porting Node debugging recipes that combine both.
Related errors
- ERR_INSPECTOR_NOT_ACTIVE
- Expected data to be a string, Buffer, Uint8Array, or ArrayBu
- ERR_INSPECTOR_ALREADY_CONNECTED
- ERR_INSPECTOR_NOT_WORKER
- ERR_INSPECTOR_NOT_CONNECTED
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/56dd48510bc98803.
Report an issue: GitHub.