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
The Node environment performs the same customExportConditions validation as the JSDOM base (default `['node','node-addons']`). It throws at index.ts:211 when the value is present but not an Array<string>, preventing a malformed resolver config from silently resolving the wrong package entry.
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 f49721c78e)
Solutions
- Use an array of strings, e.g. `customExportConditions: ['node', 'node-addons']`.
- Drop the option to keep the environment defaults.
- Validate the config shape with a startup check that `Array.isArray` and `every(isString)`.
Example fix
// before
testEnvironmentOptions: { customExportConditions: 'node' }
// after
testEnvironmentOptions: { customExportConditions: ['node'] } Defensive patterns
Strategy: validation
Validate before calling
const opts = config.testEnvironmentOptions?.customExportConditions;
if (opts != null && (!Array.isArray(opts) || opts.every === undefined || !opts.every((x: unknown) => typeof x === 'string'))) {
throw new TypeError('customExportConditions must be string[]');
} Type guard
const isStringArray = (v: unknown): v is string[] => Array.isArray(v) && v.every(x => typeof x === 'string');
Prevention
- Use the default unless you explicitly need a custom condition.
- Lint config files for non-array customExportConditions.
When it happens
Trigger: Setting `testEnvironmentOptions.customExportConditions` to a non-array or to an array containing non-strings while using `jest-environment-node`.
Common situations: Sharing a config across environments where one path used a string; tooling that injects a single condition string; misreading the docs and passing `'node-addons'` instead of `['node-addons']`.
Related errors
- Custom export conditions specified but they are not an array
- jest.config.mts requires native TypeScript support. Ensure y
- JSDOM did not return a Window object
- Resolver located at ${resolver} does not export anything
- Resolver located at ${resolver} does not export a function o
AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03).
Data as JSON: /data/errors/8835300b461a195c.json.
Report an issue: GitHub.