ERR_ENCODING_NOT_SUPPORTED
Node.jsERRORNotableEncodingHIGH confidence

The specified encoding is not supported

Production Risk

Low — caught at construction time; use iconv-lite for non-standard encodings.

What this means

Thrown when an encoding name passed to TextDecoder, TextEncoder, or other encoding-aware APIs is not a supported encoding. Node.js supports a subset of the WHATWG Encoding Standard; unsupported or misspelled encoding names produce this error.

Why it happens
  1. 1Passing an unsupported encoding name like "utf-32" to TextDecoder
  2. 2Typo in the encoding name (e.g. "utf8" without hyphen where "utf-8" is needed)
  3. 3Using an encoding only available in the browser (e.g. "x-user-defined")
How to reproduce

Triggered when an encoding-aware constructor or method receives an unrecognised encoding name.

trigger — this will error
trigger — this will error
new TextDecoder('utf-32'); // utf-32 is not supported in Node.js

expected output

RangeError [ERR_ENCODING_NOT_SUPPORTED]: The "utf-32" encoding is not supported

Fix 1

Use a supported encoding name

WHEN When constructing TextDecoder or using encoding-aware APIs

Use a supported encoding name
// Supported encodings include:
const d1 = new TextDecoder('utf-8');
const d2 = new TextDecoder('utf-16le');
const d3 = new TextDecoder('latin1');

Why this works

Using an encoding from the WHATWG supported list satisfies the validation.

Fix 2

Use iconv-lite for exotic encodings

WHEN When you need an encoding Node.js does not natively support

Use iconv-lite for exotic encodings
const iconv = require('iconv-lite');
const text = iconv.decode(buffer, 'UTF-32LE');

Why this works

iconv-lite supports many encodings beyond the WHATWG subset built into Node.js.

Code examples
Triggerjs
new TextDecoder('utf-32'); // utf-32 is not supported in Node.js  // this triggers ERR_ENCODING_NOT_SUPPORTED
Handle in try/catchjs
try {
  // operation that may throw ERR_ENCODING_NOT_SUPPORTED
  riskyOperation()
} catch (err) {
  if (err.code === 'ERR_ENCODING_NOT_SUPPORTED') {
    console.error('ERR_ENCODING_NOT_SUPPORTED:', err.message)
  } else {
    throw err
  }
}
Defensive pattern to avoid itjs
// Validate inputs before calling the operation
function safe_err_encoding_not_supported(...args) {
  // validate args here
  return performOperation(...args)
}
What not to do

Assume all browser-supported encodings are available in Node.js

Node.js implements only the WHATWG required encodings; exotic ones require a third-party library.

Sources
Official documentation ↗

Node.js Error Codes Documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Node.js errors