google/zx · error · Fail

Blob is not supported in this environment. Provide a polyfil

Error message

Blob is not supported in this environment. Provide a polyfill

What it means

Thrown by ProcessOutput.blob() when globalThis.Blob is undefined in the current runtime. Node exposes a global Blob from v15.7+ (stable from v16.7+); older Node versions or non-Node/edge runtimes may lack it, so zx asks for a polyfill before calling blob().

Source

Thrown at src/core.ts:946

  get [Symbol.toStringTag](): string {
    return 'ProcessOutput'
  }

  get ok(): boolean {
    return !this._dto.error && this.exitCode === 0
  }

  json<T = any>(): T {
    return JSON.parse(this.stdall)
  }

  buffer(): Buffer {
    return Buffer.from(this.stdall)
  }

  blob(type = 'text/plain'): Blob {
    if (!globalThis.Blob)
      throw new Fail(
        'Blob is not supported in this environment. Provide a polyfill'
      )
    return new Blob([this.buffer() as BlobPart], { type })
  }

  text(encoding: Encoding = 'utf8'): string {
    return encoding === 'utf8'
      ? this.toString()
      : this.buffer().toString(encoding)
  }

  lines(delimiter?: string | RegExp): string[] {
    return iteratorToArray(this[Symbol.iterator](delimiter))
  }

  override toString(): string {
    return this.stdall
  }

View on GitHub (pinned to 00a2c484e2)

Solutions

  1. Upgrade Node to >= 18 (current LTS).
  2. Polyfill from node:buffer: `import { Blob } from 'node:buffer'; globalThis.Blob ??= Blob`.
  3. Avoid blob() — use output.buffer() or output.text() which do not require Blob.

Example fix

// before (Node < 16.7)
const b = output.blob()
// after: polyfill from node:buffer
import { Blob } from 'node:buffer'
globalThis.Blob ??= Blob
const b = output.blob()
Defensive patterns

Strategy: type-guard

Validate before calling

function ensureBlobPolyfill(): void {
  if (typeof globalThis.Blob === 'undefined') {
    const { Blob } = require('node:buffer')
    globalThis.Blob = Blob
  }
}

ensureBlobPolyfill()
const b = output.blob()

Type guard

const hasBlob = (g: typeof globalThis): g is typeof globalThis & { Blob: typeof Blob } =>
  typeof g.Blob === 'function'

Try / catch

try {
  output.blob()
} catch (e) {
  if (e instanceof Fail && /Blob is not supported/.test(e.message)) {
    // fall back to buffer()
    return output.buffer()
  }
  throw e
}

Prevention

When it happens

Trigger: Calling `output.blob()` on Node < 16.7, or in a JS runtime/embedded engine without a Blob constructor; using a bundler configuration that strips node:buffer globals.

Common situations: Legacy Node in CI pipelines; embedded JS engines; stripped/minimal runtimes; older Lambda/container base images.

Related errors


AI-assisted analysis of google/zx@00a2c484e2 (2026-08-13). Data as JSON: /api/errors/9a816076d95c4d65. Report an issue: GitHub.