{"record":{"id":"4723562d3cddfe86","repo":"denoland/deno","slug":"err-illegal-constructor-472356","errorCode":"ERR_ILLEGAL_CONSTRUCTOR","errorMessage":"Illegal constructor","messagePattern":"Illegal constructor","errorType":"exception","errorClass":"ERR_ILLEGAL_CONSTRUCTOR","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/stream.ts","lineNumber":93,"sourceCode":");\nconst { ERR_ILLEGAL_CONSTRUCTOR } = core.loadExtScript(\n  \"ext:deno_node/internal/errors.ts\",\n);\n\nStream.isDestroyed = utils.isDestroyed;\nStream.isDisturbed = utils.isDisturbed;\nStream.isErrored = utils.isErrored;\nStream.isReadable = utils.isReadable;\nStream.isWritable = utils.isWritable;\n\nStream.Readable = Readable;\nconst streamKeys = ObjectKeys(streamReturningOperators);\nfor (let i = 0; i < streamKeys.length; i++) {\n  const key = streamKeys[i];\n  const op = streamReturningOperators[key];\n  function fn(...args) {\n    if (new.target) {\n      throw new ERR_ILLEGAL_CONSTRUCTOR();\n    }\n    return Stream.Readable.from(ReflectApply(op, this, args));\n  }\n  ObjectDefineProperty(fn, \"name\", { __proto__: null, value: op.name });\n  ObjectDefineProperty(fn, \"length\", { __proto__: null, value: op.length });\n  ObjectDefineProperty(Stream.Readable.prototype, key, {\n    __proto__: null,\n    value: fn,\n    enumerable: false,\n    configurable: true,\n    writable: true,\n  });\n}\nconst promiseKeys = ObjectKeys(promiseReturningOperators);\nfor (let i = 0; i < promiseKeys.length; i++) {\n  const key = promiseKeys[i];\n  const op = promiseReturningOperators[key];\n  function fn(...args) {","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/stream.ts#L75-L111","documentation":"The stream compat layer exposes stream-returning operators (pipeline/compose-style helpers) as methods installed on `Stream.Readable.prototype`. Each generated wrapper checks `new.target` and throws ERR_ILLEGAL_CONSTRUCTOR when invoked with `new`, because these are plain factory functions, not classes — their whole job is to call the operator and wrap its result in `Readable.from` or similar.","triggerScenarios":"`new readable.compose(other)` or any `new`-invocation of an operator method from the streamReturningOperators set installed on Readable.prototype.","commonSituations":"Code generators or bundlers that wrap functions in classes; developers assuming every exported stream helper is a class like `new Stream.Readable()`; TypeScript typings that mistakenly declare these methods constructable.","solutions":["Call the operator without `new`: `const merged = a.compose(b);`","Wrap operators in functions, not classes, when building utilities","Fix typings: these are `(...args: any[]) => Readable` signatures with no construct signature"],"exampleFix":"// before\nconst merged = new a.compose(b);\n// ERR_ILLEGAL_CONSTRUCTOR\n\n// after\nconst merged = a.compose(b);","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat stream operator methods (compose, pipeline-style helpers on Readable.prototype) as plain functions","Never use `new` with prototype-installed helpers — only Stream.Readable itself is constructable","Keep typings function-shaped so TypeScript rejects `new` at compile time"],"tags":["stream","constructor","operators","node-compat"],"backgroundTag":"illegal-constructor-call","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}