mozilla/pdf.js · error · Error

Unsupported number of components: ${numComps}

Error message

Unsupported number of components: ${numComps}

What it means

Thrown by the IccColorSpace constructor when numComps (number of color components) is not 1 (Gray), 3 (RGB), or 4 (CMYK). QCMS only knows how to transform these four input data types; any other component count has no corresponding DataType and is rejected before a transformer is created.

Source

Thrown at src/core/icc_colorspace.js:89

            this.#transformer,
            src[srcOffset] * 255,
            src[srcOffset + 1] * 255,
            src[srcOffset + 2] * 255
          );
        break;
      case 4:
        inType = DataType.CMYK;
        this.#convertPixel = (src, srcOffset) =>
          qcms_convert_four(
            this.#transformer,
            src[srcOffset] * 255,
            src[srcOffset + 1] * 255,
            src[srcOffset + 2] * 255,
            src[srcOffset + 3] * 255
          );
        break;
      default:
        throw new Error(`Unsupported number of components: ${numComps}`);
    }
    this.#transformer = qcms_transformer_from_memory(
      iccProfile,
      inType,
      Intent.Perceptual
    );
    if (!this.#transformer) {
      throw new Error("Failed to create ICC color space");
    }
    IccColorSpace.#finalizer ||= new FinalizationRegistry(transformer => {
      qcms_drop_transformer(transformer);
    });
    IccColorSpace.#finalizer.register(this, this.#transformer);
  }

  getRgbHex(src, srcOffset) {
    const color = this.#convertPixel(src, srcOffset);
    return Util.makeHexColor(color >> 16, (color >> 8) & 0xff, color & 0xff);

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Pre-convert the source PDF's images to a standard Gray/RGB/CMYK ICC profile before rendering.
  2. If you control the PDF, ensure ICCBased color spaces declare N as 1, 3, or 4.
  3. Catch the error and fall back to a non-ICC rendering path (disable useWasm/useWorkerFetch to skip ICC).
  4. Report the file to pdf.js if a standard profile triggers it.
Defensive patterns

Strategy: validation

Validate before calling

// Validate ICC color space component counts you embed/parse.
function isSupportedIccComponentCount(n) {
  return n === 1 || n === 3 || n === 4;
}

Type guard

function isQcmsSupportedComponents(numComps) {
  return numComps === 1 || numComps === 3 || numComps === 4;
}

Try / catch

try { await page.render({ canvasContext }).promise; }
catch (err) {
  if (/Unsupported number of components/.test(err?.message || '')) {
    console.warn('ICC profile has unsupported channel count; skipping image.');
  } else throw err;
}

Prevention

When it happens

Trigger: An ICCBased color space dictionary whose N (number of components) is a value like 2, 5, or 6 is parsed. Reached when rendering a PDF whose ICC profile declares an unusual channel count (e.g. multi-channel or Lab-derived ICC profiles).

Common situations: Specialized ICC profiles (Lab, multi-channel, device-link with >4 channels) embedded in PDFs; corrupt N values from a damaged dict; PDFs generated by color-management tools that emit non-standard component counts.

Related errors


AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13). Data as JSON: /api/errors/5fe7e13acb676bf1. Report an issue: GitHub.