{"record":{"id":"bb53e62e96a32896","repo":"denoland/deno","slug":"err-invalid-arg-type-bb53e6","errorCode":"ERR_INVALID_ARG_TYPE","errorMessage":"The \"${name}\" argument must be of type object. Received ${value}","messagePattern":"The \"(.+?)\" argument must be of type object\\. Received (.+?)","errorType":"validation","errorClass":"ERR_INVALID_ARG_TYPE","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/wasi.ts","lineNumber":93,"sourceCode":"    `The \"instance.exports.memory\" property must be a WebAssembly.Memory object. Received ${received}`,\n  );\n  (err as unknown as { code: string }).code = \"ERR_INVALID_ARG_TYPE\";\n  return err;\n}\n\nclass WASIProcExit {\n  code: number;\n  constructor(code: number) {\n    this.code = code;\n  }\n}\n\nfunction validateObject(\n  value: unknown,\n  name: string,\n): asserts value is object {\n  if (value === null || typeof value !== \"object\" || ArrayIsArray(value)) {\n    throw new ERR_INVALID_ARG_TYPE(name, \"object\", value);\n  }\n}\n\nfunction validateArray(\n  value: unknown,\n  name: string,\n): asserts value is unknown[] {\n  if (!ArrayIsArray(value)) {\n    throw new ERR_INVALID_ARG_TYPE(name, \"Array\", value);\n  }\n}\n\nfunction validateBoolean(\n  value: unknown,\n  name: string,\n): asserts value is boolean {\n  if (typeof value !== \"boolean\") {\n    throw new ERR_INVALID_ARG_TYPE(name, \"boolean\", value);","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/wasi.ts#L75-L111","documentation":"Local validateObject in the WASI polyfill (wasi.ts:88-95) throws ERR_INVALID_ARG_TYPE for the WASI constructor's `options`, `options.env`, and `options.preopens` when the value is null, not an object, or an Array. It is stricter than a plain typeof check — arrays are explicitly rejected even though typeof [] === 'object'.","triggerScenarios":"`new WASI(null)`; `new WASI(new SomeClass())` is fine but `new WASI('preview1')` (string) is not; `env: [['A','1']]` as an array of pairs instead of a map object; `preopens: ['/tmp']` as an array instead of `{ virtual: real }`; `env: 'A=1'` shell-style strings.","commonSituations":"Transluting shell/env semantics into options: developers pass env as `KEY=VALUE` strings or entry arrays (child_process.spawn style) instead of an object map; passing preopens as an array of paths; deserialized JSON options where env became null; mixing up spawn({env}) object style with exec string style.","solutions":["Use object maps: `new WASI({ version: 'preview1', env: { A: '1' }, preopens: { '/sandbox': './data' } })`","Convert pair arrays first: `Object.fromEntries(pairs)`","Default missing maps explicitly: `env: envMap ?? {}`","Reject arrays at the boundary if your config layer might deliver them"],"exampleFix":"// before\nnew WASI({ version: 'preview1', env: [['A','1']], preopens: ['/data'] });\n// after\nnew WASI({\n  version: 'preview1',\n  env: Object.fromEntries([['A', '1']]),\n  preopens: { '/data': './data' },\n});","handlingStrategy":"type-guard","validationCode":"const isPlainObject = (v) =>\n  typeof v === 'object' && v !== null && !Array.isArray(v);\nif (!isPlainObject(opts.env)) opts.env = {};\nif (!isPlainObject(opts.preopens)) opts.preopens = {};\nnew WASI({ version: 'preview1', ...opts });","typeGuard":"const isPlainObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);","tryCatchPattern":"try { new WASI(opts); }\ncatch (e) { if (e.code === 'ERR_INVALID_ARG_TYPE' && /env|preopens|options/.test(e.message)) { /* convert pair arrays with Object.fromEntries and retry */ } else throw e; }","preventionTips":["Use object maps for env and preopens, never KEY=VALUE strings or pair arrays","Normalize deserialized config at load time (null -> {})","Remember arrays are rejected where objects are expected"],"tags":["wasi","webassembly","type-validation","node-compat"],"backgroundTag":"invalid-argument-value","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}