Version
v26.1.0
Platform
Subsystem
assert
What steps will reproduce the bug?
Save the following as repro.mjs:
import { strict as assert } from 'node:assert';
try {
assert(false);
} catch (e) {
console.log(e.constructor.name, e.code, JSON.stringify(e.message));
}
Run it under Node.js v26.0.0 or later, with and without --enable-source-maps:
$ node repro.mjs
AssertionError ERR_ASSERTION "The expression evaluated to a falsy value:\n\n assert(false)\n"
$ node --enable-source-maps repro.mjs
TypeError ERR_INVALID_ARG_TYPE "The \"message\" argument must be one of type string or function. Received undefined"
The same TypeError is thrown for assert.ok(false) and assert.strict(false). It does not appear for assert.equal, assert.strictEqual, and so on — only the auto-generated-message path used by assert(value) / assert.ok(value) is affected.
The same script on Node.js v25.9.0 (with --enable-source-maps) prints AssertionError as expected.
How often does it reproduce? Is there a required condition?
100%. The required conditions are:
- Node.js v26.0.0 or v26.1.0
--enable-source-maps is enabled.
- The script that performs the assertion has no source map registered for it.
- A failing
assert(value) or assert.ok(value) is executed without an explicit message argument.
What is the expected behavior? Why is that the expected behavior?
The same as Node.js v25.x: a failing assert(value) should throw an AssertionError instead of throwing a TypeError.
What do you see instead?
A TypeError [ERR_INVALID_ARG_TYPE]: The "message" argument must be one of type string or function. Received undefined is thrown from inside internal/assert/utils.js, before any AssertionError is constructed:
TypeError [ERR_INVALID_ARG_TYPE]: The "message" argument must be one of type string or function. Received undefined
at innerFail (node:internal/assert/utils:135:11)
at innerOk (node:internal/assert/utils:169:5)
at strict (node:assert:882:3)
...
Additional information
When --enable-source-maps is on but no source map is registered for the script (typical for a hand-written .mjs / .cjs file), getErrorSourceLocation in lib/internal/errors/error_source.js returns undefined, then getErrMessage in lib/internal/assert/utils.js returns undefined, then innerOk passes [undefined] to the new strict innerFail, and innerFail throws ERR_INVALID_ARG_TYPE.
Version
v26.1.0
Platform
Subsystem
assert
What steps will reproduce the bug?
Save the following as
repro.mjs:Run it under Node.js v26.0.0 or later, with and without
--enable-source-maps:The same
TypeErroris thrown forassert.ok(false)andassert.strict(false). It does not appear forassert.equal,assert.strictEqual, and so on — only the auto-generated-message path used byassert(value)/assert.ok(value)is affected.The same script on Node.js v25.9.0 (with
--enable-source-maps) printsAssertionErroras expected.How often does it reproduce? Is there a required condition?
100%. The required conditions are:
--enable-source-mapsis enabled.assert(value)orassert.ok(value)is executed without an explicitmessageargument.What is the expected behavior? Why is that the expected behavior?
The same as Node.js v25.x: a failing
assert(value)should throw anAssertionErrorinstead of throwing aTypeError.What do you see instead?
A
TypeError [ERR_INVALID_ARG_TYPE]: The "message" argument must be one of type string or function. Received undefinedis thrown from insideinternal/assert/utils.js, before anyAssertionErroris constructed:Additional information
When
--enable-source-mapsis on but no source map is registered for the script (typical for a hand-written.mjs/.cjsfile),getErrorSourceLocationinlib/internal/errors/error_source.jsreturnsundefined, thengetErrMessageinlib/internal/assert/utils.jsreturnsundefined, theninnerOkpasses[undefined]to the new strictinnerFail, andinnerFailthrowsERR_INVALID_ARG_TYPE.