jestjs/jest · error · Error

Custom export conditions specified but they are not an array

Error message

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

What it means

BaseJSDOMEnvironment reads `testEnvironmentOptions.customExportConditions` and requires it to be an Array where every element is a string; otherwise it throws at index.ts:150. These conditions drive package.json `exports` resolution (default `['browser']`), so a malformed value would silently break module resolution.

Source

Thrown at packages/jest-environment-jsdom-abstract/src/index.ts:150

    };
    global.removeEventListener = function (
      ...args: Parameters<typeof originalRemoveListener>
    ) {
      if (args[0] === 'error') {
        userErrorListenerCount--;
      }
      return originalRemoveListener.apply(this, args);
    };

    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: (id: number) => id,
        refToId: (ref: number) => ref,
      },
    });

    this.fakeTimersModern = new ModernFakeTimers({

View on GitHub (pinned to f49721c78e)

Solutions

  1. Set the value to an array of strings, e.g. `customExportConditions: ['browser']`.
  2. Remove the key entirely to accept the environment default (`['browser']`).
  3. If overriding per-file via docblock, JSON-encode the array: `{"customExportConditions": ["browser"]}`.

Example fix

// before
/**
 * @jest-environment jsdom
 * @jest-environment-options {"customExportConditions": "browser"}
 */

// after
/**
 * @jest-environment jsdom
 * @jest-environment-options {"customExportConditions": ["browser"]}
 */
Defensive patterns

Strategy: validation

Validate before calling

const opts = config.testEnvironmentOptions?.customExportConditions;
if (opts != null && (!Array.isArray(opts) || !opts.every(v => typeof v === 'string'))) {
  throw new Error('customExportConditions must be string[]');
}

Type guard

const isExportConditions = (v: unknown): v is string[] => Array.isArray(v) && v.every(x => typeof x === 'string');

Prevention

When it happens

Trigger: Setting `customExportConditions: 'browser'` (string instead of array), `customExportConditions: [42]`, or `customExportConditions: {import: 'browser'}` via `@jest-environment-options` docblock or jest.config.

Common situations: Copy-paste from a doc snippet that quotes a single condition; mixing up `testEnvironmentOptions` with `testEnvironment`; passing a TS enum or object expecting it to coerce.

Related errors


AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03). Data as JSON: /data/errors/9941f5d2146fca6d.json. Report an issue: GitHub.