remix-run/remix · error · Error

Unsupported encoding: ${encoding}

Error message

Unsupported encoding: ${encoding}

What it means

The response compression helper maps an `encoding` value to a zlib compressor and only supports 'br', 'gzip', and 'deflate'. The switch reached its default branch, meaning an unrecognized encoding string was passed. This is a programming/config error in how the compressor was requested, not a runtime environment issue.

Source

Thrown at packages/response/src/lib/compress.ts:367

      compressor.destroy()
      await reader?.cancel(reason)
    },
  })
}

function createCompressor(
  encoding: Encoding,
  options: CompressResponseOptions,
): Gzip | Deflate | BrotliCompress {
  switch (encoding) {
    case 'br':
      return createBrotliCompress(options.brotli)
    case 'gzip':
      return createGzip(options.zlib)
    case 'deflate':
      return createDeflate(options.zlib)
    default:
      throw new Error(`Unsupported encoding: ${encoding}`)
  }
}

View on GitHub (pinned to 9696913134)

Solutions

  1. Pass only 'br', 'gzip', or 'deflate'
  2. If deriving from Accept-Encoding, parse and pick from the supported set before calling
  3. Normalize case (lowercase) before passing the value
  4. File/await support for additional encodings rather than bypassing the guard

Example fix

// before
let compressor = createCompressor(request.headers.get('accept-encoding'))

// after
let accepted = request.headers.get('accept-encoding') ?? ''
let encoding = ['br','gzip','deflate'].find(e => accepted.includes(e)) ?? 'gzip'
let compressor = createCompressor(encoding)
Defensive patterns

Strategy: type-guard

Validate before calling

const SUPPORTED = new Set(['br', 'gzip', 'deflate'])
let encoding = rawEncoding.toLowerCase()
if (!SUPPORTED.has(encoding)) encoding = 'gzip'

Type guard

function isSupportedEncoding(value: string): value is 'br' | 'gzip' | 'deflate' {
  return value === 'br' || value === 'gzip' || value === 'deflate'
}

Prevention

When it happens

Trigger: Calling the compress API (createCompressor / the `compressor` helper) with an `encoding` other than 'br'/'brotli', 'gzip', or 'deflate' — e.g. 'zstd', 'identity', an empty string, or a value sourced from a request Accept-Encoding header without filtering.

Common situations: Forwarding a client's Accept-Encoding header directly as the chosen encoding; adding zstd support before the library supports it; case mismatches like 'GZIP' from a custom config.


AI-assisted analysis of remix-run/remix@9696913134 (2026-08-27). Data as JSON: /api/errors/4c397caa1f405eab. Report an issue: GitHub.