jestjs/jest · error · Error

Custom export conditions specified but they are not an…

Error message

Custom export conditions specified but they are not an array of strings

What it means

Thrown by the Node environment constructor when `testEnvironmentOptions.customExportConditions` is present but is not an array of strings. Same validation logic as the jsdom environment — `Array.isArray(...) && every(isString)`. The default for node is `['node', 'node-addons']`.

Solutions

  1. Set `customExportConditions` to an array of strings: `['node', 'node-addons']`.
  2. Remove the option if the default conditions are acceptable.
  3. Validate the type with `Array.isArray()` before committing config changes.

Example fix

// before
module.exports = {
  testEnvironment: 'node',
  testEnvironmentOptions: { customExportConditions: 'node' },
};

// after
module.exports = {
  testEnvironment: 'node',
  testEnvironmentOptions: { customExportConditions: ['node'] },
};
Defensive patterns

Strategy: type-guard

Validate before calling

// Same validation for node environment
function validateNodeExportConditions(opts) {
  if ('customExportConditions' in opts) {
    const c = opts.customExportConditions;
    if (!Array.isArray(c) || !c.every(v => typeof v === 'string')) {
      throw new TypeError('customExportConditions must be an array of strings');
    }
  }
}

Type guard

function isStringArray(value: unknown): value is string[] {
  return Array.isArray(value) && value.every(v => typeof v === 'string');
}

Prevention

When it happens

Trigger: Setting `testEnvironmentOptions: { customExportConditions: 'node' }` (string) or `{ customExportConditions: ['node', 42] }` (mixed types) in jest.config.js when using `testEnvironment: 'node'`.

Common situations: Same as error 92 but in node environment context. Typing the value as a string or object. Configuring conditions for dual-package exports (ESM/CJS) with the wrong type.

Related errors


AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10). Data as JSON: /api/errors/8835300b461a195c. Report an issue: GitHub.

Appendix: source

Thrown at packages/jest-environment-node/src/index.ts:211

      // @ts-expect-error - it's readonly - but we have checked above that it's not there
      globalSymbol.asyncDispose = globalSymbol.for('nodejs.asyncDispose');
      // @ts-expect-error - it's readonly - but we have checked above that it's not there
      globalSymbol.dispose = globalSymbol.for('nodejs.dispose');
    }

    // Node's error-message stack size is limited at 10, but it's pretty useful
    // to see more than that when a test fails.
    global.Error.stackTraceLimit = 100;

    if ('customExportConditions' in projectConfig.testEnvironmentOptions) {
      const {customExportConditions} = projectConfig.testEnvironmentOptions;
      if (
        Array.isArray(customExportConditions) &&
        customExportConditions.every(isString)
      ) {
        this._configuredExportConditions = customExportConditions;
      } else {
        throw new Error(
          'Custom export conditions specified but they are not an array of strings',
        );
      }
    }

    this.moduleMocker = new ModuleMocker(global);

    this.fakeTimers = new LegacyFakeTimers({
      config: projectConfig,
      global,
      moduleMocker: this.moduleMocker,
      timerConfig: {
        idToRef: timerIdToRef,
        refToId: timerRefToId,
      },
    });

    this.fakeTimersModern = new ModernFakeTimers({

View on GitHub (pinned to 8e6d128e4a)