lovell/sharp · error · Error

Unsupported input '${input}' of type ${typeof input}${is.def

Error message

Unsupported input '${input}' of type ${typeof input}${is.defined(inputOptions) ? ` when also providing options of type ${typeof inputOptions}` : ''}

What it means

The catch-all thrown when the input value does not match any recognized input type (file path string, Buffer, Uint8Array, Stream, ReadStream, or Array for joins). The message interpolates the actual input and its typeof, plus the options type if options were also passed, so the developer can see exactly what was rejected. It is the final else branch after all specific input handlers.

Source

Thrown at lib/input.mjs:105

      inputDescriptor.buffer = [];
    }
  } else if (!is.defined(input) && !is.defined(inputOptions) && is.object(containerOptions) && containerOptions.allowStream) {
    // Stream without options
    inputDescriptor.buffer = [];
  } else if (Array.isArray(input)) {
    if (input.length > 1) {
      // Join images together
      if (!this.options.joining) {
        this.options.joining = true;
        this.options.join = input.map(i => this._createInputDescriptor(i));
      } else {
        throw new Error('Recursive join is unsupported');
      }
    } else {
      throw new Error('Expected at least two images to join');
    }
  } else {
    throw new Error(`Unsupported input '${input}' of type ${typeof input}${
      is.defined(inputOptions) ? ` when also providing options of type ${typeof inputOptions}` : ''
    }`);
  }
  if (is.object(inputOptions)) {
    // failOn
    if (is.defined(inputOptions.failOn)) {
      if (is.string(inputOptions.failOn) && is.inArray(inputOptions.failOn, ['none', 'truncated', 'error', 'warning'])) {
        inputDescriptor.failOn = inputOptions.failOn;
      } else {
        throw is.invalidParameterError('failOn', 'one of: none, truncated, error, warning', inputOptions.failOn);
      }
    }
    // autoOrient
    if (is.defined(inputOptions.autoOrient)) {
      if (is.bool(inputOptions.autoOrient)) {
        inputDescriptor.autoOrient = inputOptions.autoOrient;
      } else {
        throw is.invalidParameterError('autoOrient', 'boolean', inputOptions.autoOrient);

View on GitHub (pinned to 56676c6918)

Solutions

  1. Pass a recognized input type: string path, Buffer, Uint8Array, Stream, or Array.
  2. Coerce URL objects to strings: sharp(url.toString()) or sharp(url.href).
  3. If reading from an async source, await/resolve it to a Buffer or Stream first, then pass that to sharp.
  4. Read the interpolated message: it tells you both the value and typeof, which pinpoints the mismatch.

Example fix

// before
sharp({ src: './img.png' })

// after
sharp('./img.png')
Defensive patterns

Strategy: type-guard

Validate before calling

function toSharpInput(value) {
  if (typeof value === 'string') return value;
  if (Buffer.isBuffer(value) || value instanceof Uint8Array) return value;
  if (value && typeof value.pipe === 'function') return value;
  if (Array.isArray(value)) return value;
  if (value instanceof URL) return value.href;
  throw new Error(`Unsupported sharp input of type ${typeof value}`);
}

Type guard

function isSupportedSharpInput(v) {
  return typeof v === 'string' || Buffer.isBuffer(v) || v instanceof Uint8Array ||
    (v && typeof v.pipe === 'function') || Array.isArray(v);
}

Prevention

When it happens

Trigger: Passing a number, plain object, boolean, function, or BigInt as input: sharp(42), sharp({}), sharp(true). Passing a Promise or async iterable. Passing a URL object instead of a string path.

Common situations: Confusing sharp's input contract with another library (e.g., expecting sharp({ src: path })). Passing a parsed URL object rather than url.toString(). Feeding a non-thenable wrapper object from an ORM or file abstraction layer.

Related errors


AI-assisted analysis of lovell/sharp@56676c6918 (2026-08-13). Data as JSON: /api/errors/428dc5bbe87706a4. Report an issue: GitHub.