denoland/deno · error · TypeError

ERR_INVALID_ARG_VALUE

ERR_INVALID_ARG_VALUE

Error message

The argument 'colorMode' must be one of: 'auto', true, false. Received ${colorMode}

What it means

The Console constructor's colorMode option accepts exactly three values: true, false, or the string 'auto'. Anything else - 'always', 'yes', 1, null, 'TRUE' - throws ERR_INVALID_ARG_VALUE at construction. The check is strict about type and case, matching Node's lib/internal/console/constructor.js.

Source

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

    stdout,
    stderr = stdout,
    ignoreErrors = true,
    colorMode = "auto",
    inspectOptions,
    groupIndentation,
  } = options;

  if (!stdout || typeof stdout.write !== "function") {
    throw new ERR_CONSOLE_WRITABLE_STREAM("stdout");
  }
  if (!stderr || typeof stderr.write !== "function") {
    throw new ERR_CONSOLE_WRITABLE_STREAM("stderr");
  }

  if (typeof colorMode !== "boolean" && colorMode !== "auto") {
    // Match Node: reason lists the accepted values (see
    // lib/internal/console/constructor.js).
    throw new ERR_INVALID_ARG_VALUE(
      "colorMode",
      colorMode,
      "must be one of: 'auto', true, false",
    );
  }

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

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

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Normalize before constructing: const colorMode = forceColor ? true : 'auto'
  2. Restrict your config schema to true | false | 'auto' and validate early
  3. Omit colorMode entirely - the default 'auto' detects TTY correctly in most cases
  4. Map common inputs explicitly: FORCE_COLOR=0 -> false, FORCE_COLOR=1/true -> true, unset -> 'auto'

Example fix

// before
const logger = new Console({ stdout, colorMode: process.env.FORCE_COLOR }); // '1' -> ERR_INVALID_ARG_VALUE

// after
const raw = process.env.FORCE_COLOR;
const colorMode = raw === undefined ? 'auto' : raw !== '0';
const logger = new Console({ stdout, colorMode });
Defensive patterns

Strategy: validation

Validate before calling

function normalizeColorMode(v) {
  if (v === undefined) return 'auto';
  if (v === 'auto' || typeof v === 'boolean') return v;
  throw new TypeError(`colorMode must be 'auto', true, or false; got ${String(v)}`);
}
const logger = new Console({ stdout, colorMode: normalizeColorMode(cfg.colorMode) });

Type guard

const isValidColorMode = (v) => v === 'auto' || v === true || v === false;

Try / catch

try {
  logger = new Console({ stdout, colorMode: cfg.colorMode });
} catch (e) {
  if (e?.code === 'ERR_INVALID_ARG_VALUE') logger = new Console({ stdout });
  else throw e;
}

Prevention

When it happens

Trigger: new Console({ stdout, colorMode: 'always' }) (unrecognized string); colorMode: 1 (number, not boolean); colorMode: null; colorMode wired straight from an env var like process.env.FORCE_COLOR ('1') without normalization.

Common situations: Mapping CLI flags or env variables (FORCE_COLOR, NO_COLOR, TERM) to colorMode without converting; assuming chalk-style 'always' is accepted; config schemas that allow free-form strings.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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