denoland/deno · error · TypeError
ERR_CONSTRUCT_CALL_REQUIRED
ERR_CONSTRUCT_CALL_REQUIRED
Error message
Class constructor Assert cannot be invoked without `new`
What it means
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.
Source
Thrown at ext/node/polyfills/assert.ts:71
ObjectPrototypeIsPrototypeOf,
ReflectApply,
ReflectHas,
RegExpPrototypeExec,
SafeArrayIterator,
StringPrototypeIndexOf,
StringPrototypeSlice,
StringPrototypeSplit,
String,
Symbol,
} = primordials;
const kOptions = Symbol("options");
const NO_EXCEPTION_SENTINEL = {};
function Assert(options) {
if (!new.target) {
throw new ERR_CONSTRUCT_CALL_REQUIRED("Assert");
}
options = ObjectAssign({
__proto__: null,
strict: true,
skipPrototype: false,
}, options);
const allowedDiffs = ["simple", "full"];
if (options.diff !== undefined) {
validateOneOf(options.diff, "options.diff", allowedDiffs);
}
this.AssertionError = AssertionError;
ObjectDefineProperty(this, kOptions, {
__proto__: null,
value: options,
enumerable: false,View on GitHub (pinned to 89f33cbef2)
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
Example fix
// before
const a = require('assert').Assert();
// after
const a = new (require('assert').Assert)({ strict: true }); Defensive patterns
Strategy: validation
Validate before calling
const assert = require('node:assert'); const a = new assert.Assert({ strict: true }); Try / catch
try { Assert(); } catch (e) { if (e.code === 'ERR_CONSTRUCT_CALL_REQUIRED') a = new Assert(); else throw e; } Prevention
- Always use new with class-style APIs
- Prefer the module-level assert export for everyday assertions
When it happens
Trigger: 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, []).
Common situations: 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.
Related errors
- ERR_ASSERTION
- ERR_INVALID_ARG_VALUE
- ERR_INVALID_RETURN_VALUE
- ERR_INVALID_ARG_TYPE
- ERR_AMBIGUOUS_ARGUMENT
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/d2dbd14476eb2320.
Report an issue: GitHub.