denoland/deno · error · TypeError

ERR_INCOMPATIBLE_OPTION_PAIR

ERR_INCOMPATIBLE_OPTION_PAIR

Error message

Option "options.inspectOptions.color" cannot be used in combination with option "colorMode"

What it means

Console rejects constructing with both colorMode and inspectOptions.colors set - they control the same color setting, so ERR_INCOMPATIBLE_OPTION_PAIR is thrown. The check fires whenever colorMode is present (even 'auto') together with inspectOptions.colors !== undefined. Note a grepping gotcha: the code checks the property 'colors' but the message says 'options.inspectOptions.color' (singular), matching Node's message verbatim.

Source

Thrown at ext/node/polyfills/internal/console/constructor.mjs:188

  }

  if (groupIndentation !== undefined) {
    validateInteger(
      groupIndentation,
      "groupIndentation",
      0,
      kMaxGroupIndentation,
    );
  }

  if (inspectOptions !== undefined) {
    validateObject(inspectOptions, "options.inspectOptions");

    if (
      inspectOptions.colors !== undefined &&
      options.colorMode !== undefined
    ) {
      throw new ERR_INCOMPATIBLE_OPTION_PAIR(
        "options.inspectOptions.color",
        "colorMode",
      );
    }
    WeakMapPrototypeSet(optionsMap, this, inspectOptions);
  }

  // Bind the prototype functions to this Console instance
  ArrayPrototypeForEach(ObjectKeys(Console.prototype), (key) => {
    // We have to bind the methods grabbed from the instance instead of from
    // the prototype so that users extending the Console can override them
    // from the prototype chain of the subclass.
    this[key] = FunctionPrototypeBind(this[key], this);
    ObjectDefineProperty(this[key], "name", {
      __proto__: null,
      value: key,
    });
  });

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Pick one knob: drop colorMode and keep inspectOptions.colors (or vice versa)
  2. Strip one side when merging configs: if (merged.inspectOptions?.colors !== undefined) delete merged.colorMode
  3. Build options conditionally: only set colorMode when inspectOptions is absent
  4. Document the chosen knob in your logging config schema so both never appear

Example fix

// before
new Console({ stdout, colorMode: 'auto', inspectOptions: { colors: true } }); // ERR_INCOMPATIBLE_OPTION_PAIR

// after
new Console({ stdout, colorMode: 'auto' });
// or equivalently:
new Console({ stdout, inspectOptions: { colors: true } });
Defensive patterns

Strategy: validation

Validate before calling

function buildConsoleOptions(cfg) {
  if (cfg.inspectOptions?.colors !== undefined) {
    const { colorMode: _drop, ...rest } = cfg;
    return rest; // colors win, colorMode removed
  }
  return cfg;
}
const logger = new Console(buildConsoleOptions(cfg));

Try / catch

try {
  logger = new Console(cfg);
} catch (e) {
  if (e?.code === 'ERR_INCOMPATIBLE_OPTION_PAIR') { delete cfg.colorMode; logger = new Console(cfg); }
  else throw e;
}

Prevention

When it happens

Trigger: new Console({ stdout, colorMode: 'auto', inspectOptions: { colors: true } }); merging a preset that sets inspectOptions.colors with user config that sets colorMode; porting code that used util.inspect colors and later added colorMode.

Common situations: Deep-merging default options with user options where each side sets a different knob; copy-pasted logger presets; incremental refactors that added colorMode without removing colors from inspectOptions.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/fbac703645a6fba2. Report an issue: GitHub.