mochajs/mocha · critical · FatalError

ERR_MOCHA_FATAL

ERR_MOCHA_FATAL

Error message

Object missing ID received in event data

What it means

ParallelBufferedRunner.linkEvent() re-hydrates serialized test objects (suites/tests/hooks) from worker events by linking them to known objects via an id. If a data object that should carry an ID lacks one, the runner cannot link it and throws a fatal ERR_MOCHA_ERROR.

Source

Thrown at lib/nodejs/parallel-buffered-runner.cjs:158

     * Given an event, recursively find any objects in its data that have ID's, and create object references to already-seen objects.
     * @param {Object} event - Event having `eventName`, maybe `data` and maybe `error`
     */
    const linkEvent = (event) => {
      const stack = [{ parent: event, prop: "data" }];
      while (stack.length) {
        const { parent, prop } = stack.pop();
        const obj = parent[prop];
        let newObj;
        if (obj && typeof obj === "object") {
          if (obj[MOCHA_ID_PROP_NAME]) {
            const id = obj[MOCHA_ID_PROP_NAME];
            newObj = this._linkedObjectMap.has(id)
              ? Object.assign(this._linkedObjectMap.get(id), obj)
              : obj;
            this._linkedObjectMap.set(id, newObj);
            parent[prop] = newObj;
          } else {
            throw createFatalError(
              "Object missing ID received in event data",
              obj,
            );
          }
        }
        Object.keys(newObj).forEach((key) => {
          const value = obj[key];
          if (value && typeof value === "object" && value[MOCHA_ID_PROP_NAME]) {
            stack.push({ obj: value, parent: newObj, prop: key });
          }
        });
      }
    };

    return async (file) => {
      debug("run(): enqueueing test file %s", file);
      try {
        const { failureCount, events } = await pool.run(file, options);

View on GitHub (pinned to 6bcbee4fd9)

Solutions

  1. Reinstall/align mocha so main and worker use the same version (npm ci)
  2. Remove or update custom reporters/plugins affecting parallel event payloads
  3. Reproduce with a minimal parallel run and file a mocha bug if it persists

Example fix

// before
// mixed mocha versions: node_modules/mocha (old) vs global mocha (new)
// after
npm ci
npx mocha --parallel --jobs 2
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await runnerPromise;
} catch (err) {
  if (String(err.message).includes('Object missing ID')) {
    console.error('Parallel event deserialization failed; check mocha version alignment and reporters');
    process.exitCode = 1;
  } else {
    throw err;
  }
}

Prevention

When it happens

Trigger: A worker emits a BufferedEvent whose object payload lacks an id property during deserialization in linkEvent(); typically indicates an internal serialization/protocol mismatch.

Common situations: Version mismatch between the mocha main process and worker code (stale install or mixed versions); custom reporters/plugins in parallel mode mutating event payloads; a genuine mocha bug in event serialization.

Related errors


AI-assisted analysis of mochajs/mocha@6bcbee4fd9 (2026-09-01). Data as JSON: /api/errors/9e2e1f6d771974f0. Report an issue: GitHub.