{"record":{"id":"34fa8672c84fcf5f","repo":"denoland/deno","slug":"err-invalid-arg-type-34fa86","errorCode":"ERR_INVALID_ARG_TYPE","errorMessage":"The \"view\" argument must be of type TypedArray. Received ${view}","messagePattern":"The \"view\" argument must be of type TypedArray\\. Received (.+?)","errorType":"error_code","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/buffer.mjs","lineNumber":342,"sourceCode":"    value,\n  );\n}\n\nconst BufferFrom = Buffer.from = function from(\n  value,\n  encodingOrOffset,\n  length,\n) {\n  return _from(value, encodingOrOffset, length);\n};\n\nBuffer.copyBytesFrom = function copyBytesFrom(\n  view,\n  offset,\n  length,\n) {\n  if (!isTypedArray(view)) {\n    throw new ERR_INVALID_ARG_TYPE(\"view\", [\"TypedArray\"], view);\n  }\n\n  const viewLength = TypedArrayPrototypeGetLength(view);\n  if (viewLength === 0) {\n    return Buffer.alloc(0);\n  }\n\n  if (offset !== undefined || length !== undefined) {\n    if (offset !== undefined) {\n      validateInteger(offset, \"offset\", 0);\n      if (offset >= viewLength) return Buffer.alloc(0);\n    } else {\n      offset = 0;\n    }\n    let end;\n    if (length !== undefined) {\n      validateInteger(length, \"length\", 0);\n      end = offset + length;","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/buffer.mjs#L324-L360","documentation":"Buffer.copyBytesFrom(view, offset, length) requires its first argument to be a TypedArray and throws ERR_INVALID_ARG_TYPE('view', ['TypedArray'], view) at buffer.mjs:342 when it is not. Common confusion: ArrayBuffer and DataView are rejected (they are not TypedArrays), while Buffer itself is accepted because it subclasses Uint8Array. The API copies bytes from a typed-array view into a new Buffer without copying the source twice.","triggerScenarios":"Buffer.copyBytesFrom(arrayBuffer) - passing the underlying ArrayBuffer instead of a view over it; Buffer.copyBytesFrom(new DataView(buf)) - DataView fails isTypedArray; Buffer.copyBytesFrom([1, 2, 3]) or a plain object with a length - ordinary arrays are rejected; a loosely typed function parameter receiving whatever the caller had handy.","commonSituations":"Interfacing with Web APIs that hand back ArrayBuffers (File.arrayBuffer(), crypto.subtle) and forwarding them directly; mixed DataView/TypedArray codebases; converting wasm memory slices.","solutions":["Wrap non-view inputs: pass new Uint8Array(arrayBuffer) instead of the ArrayBuffer itself","Type-guard at the call site: ArrayBuffer.isView(view) && !(view instanceof DataView)","For plain arrays of bytes use Buffer.from(arr) instead of copyBytesFrom","For DataView sources, construct new Uint8Array(dv.buffer, dv.byteOffset, dv.byteLength)"],"exampleFix":"// before\nconst copy = Buffer.copyBytesFrom(await file.arrayBuffer());\n\n// after\nconst copy = Buffer.copyBytesFrom(new Uint8Array(await file.arrayBuffer()));","handlingStrategy":"type-guard","validationCode":"const isTypedArray = (v) =>\n  ArrayBuffer.isView(v) && !(v instanceof DataView);\n\nif (!isTypedArray(source)) {\n  source = new Uint8Array(source); // wraps ArrayBuffer; throws on invalid input\n}\nconst copy = Buffer.copyBytesFrom(source, offset, length);","typeGuard":"const isTypedArray = (v) =>\n  ArrayBuffer.isView(v) && !(v instanceof DataView);","tryCatchPattern":null,"preventionTips":["Convert ArrayBuffer to Uint8Array at Web API boundaries (file.arrayBuffer(), crypto.subtle)","Use Buffer.from for plain arrays; reserve copyBytesFrom for typed-array views","Type the parameter as TypedArray in TypeScript signatures"],"tags":["buffer","typed-array","validation","node-compat","web-interop"],"backgroundTag":"invalid-argument-type","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-21T08:17:14.275Z"}