The specified encoding is not supported
Production Risk
Low — caught at construction time; use iconv-lite for non-standard encodings.
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.
- 1Passing an unsupported encoding name like "utf-32" to TextDecoder
- 2Typo in the encoding name (e.g. "utf8" without hyphen where "utf-8" is needed)
- 3Using an encoding only available in the browser (e.g. "x-user-defined")
Triggered when an encoding-aware constructor or method receives an unrecognised encoding name.
new TextDecoder('utf-32'); // utf-32 is not supported in Node.jsexpected 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
// 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
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.
new TextDecoder('utf-32'); // utf-32 is not supported in Node.js // this triggers ERR_ENCODING_NOT_SUPPORTEDtry {
// 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
}
}// Validate inputs before calling the operation
function safe_err_encoding_not_supported(...args) {
// validate args here
return performOperation(...args)
}✕ 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.
Node.js Error Codes Documentation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev