{"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/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/assert.ts#L53-L89","documentation":"The assert strict-mode class in Deno's node:assert polyfill must be constructed with new (ext/node/polyfills/assert.ts:71): calling Assert() as a plain function throws ERR_CONSTRUCT_CALL_REQUIRED('Assert'). Instances carry assertion options ({ strict, skipPrototype, diff }) and expose the full assertion surface (ok, equal, rejects, etc.) on their prototype, mirroring Node's class-based assert API introduced for per-instance configuration.","triggerScenarios":"const a = assert.strict; a(); is fine — the throw happens only for const A = assert.Assert; A(); without new, or subclass invocation via A.call(this) patterns; also Reflect.apply(Assert, undefined, []).","commonSituations":"Destructuring code like const { Assert } = require('assert') and calling it directly expecting a factory; bundlers or old transpilers that drop `new` from class calls; copy-pasted snippets targeting Node's older function-style API.","solutions":["Always instantiate: const a = new Assert({ strict: true, diff: 'full' })","For plain strict assertions, just use the default export: const assert = require('assert').strict; assert(ok)","If you only need assert() itself, the top-level function never requires new"],"exampleFix":"// before\nconst a = require('assert').Assert();\n\n// after\nconst a = new (require('assert').Assert)({ strict: true });","handlingStrategy":"validation","validationCode":"const assert = require('node:assert'); const a = new assert.Assert({ strict: true });","typeGuard":null,"tryCatchPattern":"try { Assert(); } catch (e) { if (e.code === 'ERR_CONSTRUCT_CALL_REQUIRED') a = new Assert(); else throw e; }","preventionTips":["Always use new with class-style APIs","Prefer the module-level assert export for everyday assertions"],"tags":["assert","testing","constructor","node-compat"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}