{"id":"b171de3277aae254","repo":"node-fetch/node-fetch","slug":"failed-to-construct-headers-the-provided-value","errorCode":null,"errorMessage":"Failed to construct 'Headers': The provided value is not of type '(sequence<sequence<ByteString>> or record<ByteString, ByteString>)'","messagePattern":"Failed to construct 'Headers': The provided value is not of type '\\(sequence<sequence<ByteString>> or record<ByteString, ByteString>\\)'","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/headers.js","lineNumber":93,"sourceCode":"\t\t\t\tresult = [...init]\n\t\t\t\t\t.map(pair => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\ttypeof pair !== 'object' || types.isBoxedPrimitive(pair)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthrow new TypeError('Each header pair must be an iterable object');\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn [...pair];\n\t\t\t\t\t}).map(pair => {\n\t\t\t\t\t\tif (pair.length !== 2) {\n\t\t\t\t\t\t\tthrow new TypeError('Each header pair must be a name/value tuple');\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn [...pair];\n\t\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\tthrow new TypeError('Failed to construct \\'Headers\\': The provided value is not of type \\'(sequence<sequence<ByteString>> or record<ByteString, ByteString>)');\n\t\t}\n\n\t\t// Validate and lowercase\n\t\tresult =\n\t\t\tresult.length > 0 ?\n\t\t\t\tresult.map(([name, value]) => {\n\t\t\t\t\tvalidateHeaderName(name);\n\t\t\t\t\tvalidateHeaderValue(name, String(value));\n\t\t\t\t\treturn [String(name).toLowerCase(), String(value)];\n\t\t\t\t}) :\n\t\t\t\tundefined;\n\n\t\tsuper(result);\n\n\t\t// Returning a Proxy that will lowercase key names, validate parameters and sort keys\n\t\t// eslint-disable-next-line no-constructor-return\n\t\treturn new Proxy(this, {\n\t\t\tget(target, p, receiver) {","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/node-fetch/node-fetch/blob/8b3320d2a7c07bce4afc6b2bf6c3bbddda85b01f/src/headers.js#L75-L111","documentation":"TypeError thrown at the end of the Headers constructor (src/headers.js:93) when init is neither null/undefined, nor a non-iterable object (Record), nor an iterable object. This is the catch-all for primitives — strings, numbers, booleans, BigInt, and boxed primitives (via types.isBoxedPrimitive) — which cannot be coerced into either of the two HeadersInit overloads.","triggerScenarios":"Passing a string like 'Content-Type: application/json'; a number, boolean, or BigInt as headers; a Symbol; boxed primitives like new Number(1); null being valid but other primitives not.","commonSituations":"Loading a raw header string from config without parsing; serialization round-trips that produced a primitive; user input that wasn't coerced to an object; misconfigured defaults where headers fall back to a primitive.","solutions":["Pass an object literal: { 'Content-Type': 'application/json' }","Parse raw header strings into [name, value] pairs first","Default headers to {} instead of '' or undefined-typed primitives when none provided","Add a typeof init === 'object' guard in your own header-builder helper"],"exampleFix":"// before\nnew Headers('Content-Type: application/json'); // throws\n\n// after\nnew Headers({ 'Content-Type': 'application/json' });","handlingStrategy":"type-guard","validationCode":"// Coerce primitives to objects\nfunction coerceHeaders(init) {\n  if (init == null || typeof init !== 'object') return {};\n  return init;\n}","typeGuard":"function isObjectHeadersInit(init) {\n  return init == null || (typeof init === 'object' && !['string','number','boolean','bigint','symbol'].includes(typeof init));\n}","tryCatchPattern":"try {\n  new Headers(init);\n} catch (e) {\n  if (/not of type/.test(e.message)) {\n    new Headers({}); // fall back to empty headers\n  }\n}","preventionTips":["Always pass object literals or arrays to the Headers constructor","Default optional headers to {} instead of undefined-primitive or ''","Parse raw 'Name: Value' strings into pairs before construction"],"tags":["headers","validation","webidl","constructor","type-coercion"],"analyzedSha":"8b3320d2a7c07bce4afc6b2bf6c3bbddda85b01f","analyzedAt":"2026-08-03T19:14:11.207Z","schemaVersion":2}