{"record":{"id":"d2dbd14476eb2320","repo":"denoland/deno","slug":"err-construct-call-required","errorCode":"ERR_CONSTRUCT_CALL_REQUIRED","errorMessage":"Class constructor Assert cannot be invoked without `new`","messagePattern":"Class constructor Assert cannot be invoked without `new`","errorType":"error_code","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/assert.ts","lineNumber":71,"sourceCode":"  ObjectPrototypeIsPrototypeOf,\n  ReflectApply,\n  ReflectHas,\n  RegExpPrototypeExec,\n  SafeArrayIterator,\n  StringPrototypeIndexOf,\n  StringPrototypeSlice,\n  StringPrototypeSplit,\n  String,\n  Symbol,\n} = primordials;\n\nconst kOptions = Symbol(\"options\");\n\nconst NO_EXCEPTION_SENTINEL = {};\n\nfunction Assert(options) {\n  if (!new.target) {\n    throw new ERR_CONSTRUCT_CALL_REQUIRED(\"Assert\");\n  }\n\n  options = ObjectAssign({\n    __proto__: null,\n    strict: true,\n    skipPrototype: false,\n  }, options);\n\n  const allowedDiffs = [\"simple\", \"full\"];\n  if (options.diff !== undefined) {\n    validateOneOf(options.diff, \"options.diff\", allowedDiffs);\n  }\n\n  this.AssertionError = AssertionError;\n  ObjectDefineProperty(this, kOptions, {\n    __proto__: null,\n    value: options,\n    enumerable: false,","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/assert.ts#L53-L89","documentation":"Deno's node:assert polyfill exposes the configurable Assert constructor (mirroring newer Node.js where assert can be instantiated with options such as strict, skipPrototype, and diff). Like any class constructor, it must be invoked with new; the explicit !new.target check throws ERR_CONSTRUCT_CALL_REQUIRED with the message 'Class constructor Assert cannot be invoked without `new`'. This is deliberately a TypeError-style misuse error, not an assertion failure.","triggerScenarios":"Calling the constructor as a plain function: Assert({ strict: true }) instead of new Assert({ strict: true }). Also reached when a bundler or transpiler lowers class construction into a plain call (Assert.call(...) / _super.call patterns), or when the constructor is extracted and invoked detached from new (e.g. const make = Assert; make(opts)).","commonSituations":"Code ported from Node versions where assert was only a plain function, so authors assume a factory call works; esbuild/babel output with targets below ES2015 rewriting class instantiation; copy-pasting docs snippets that dropped the new keyword; helper wrappers that forward constructor arguments without using Reflect.construct.","solutions":["Instantiate with new: const a = new Assert({ strict: true, skipPrototype: true }).","For plain boolean assertions, use the function API instead — assert(value, message) — no construction needed.","If a wrapper must construct dynamically, use Reflect.construct(Assert, [options]) rather than calling Assert directly.","Raise the bundler/transpiler target to ES2015+ so `new` on class constructors is preserved verbatim."],"exampleFix":"// before\nconst strictAssert = Assert({ strict: true });\n\n// after\nconst strictAssert = new Assert({ strict: true });","handlingStrategy":"validation","validationCode":"// Always instantiate the configurable assert explicitly\nconst opts = { strict: true, skipPrototype: false };\nconst a = new Assert(opts); // never Assert(opts)","typeGuard":"// Note: probing constructibility by constructing has side effects; treat as a\n// documentation-level contract instead of a runtime guard for Assert specifically.\n// For generic helpers: use `new.target`-safe invocation via Reflect.construct.\nconst constructAssert = (options) => Reflect.construct(Assert, [options]);","tryCatchPattern":"try {\n  const a = Assert(opts); // wrong form\n} catch (e) {\n  if (e.code === 'ERR_CONSTRUCT_CALL_REQUIRED') {\n    return new Assert(opts); // recover by constructing properly\n  }\n  throw e;\n}","preventionTips":["Always use `new` with the Assert constructor; keep the plain function form assert(value, message) for simple assertions.","Keep bundler/transpiler targets at ES2015 or higher so class construction is not lowered to plain calls.","When wrapping constructors dynamically, use Reflect.construct instead of invoking them as functions."],"tags":["node-compat","assert","constructor","ecmascript-class","deno"],"backgroundTag":"class-constructor-without-new","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}