{"record":{"id":"9941f5d2146fca6d","repo":"jestjs/jest","slug":"custom-export-conditions-specified-but-they-are-no","errorCode":null,"errorMessage":"Custom export conditions specified but they are not an array of strings","messagePattern":"Custom export conditions specified but they are not an array of strings","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-environment-jsdom-abstract/src/index.ts","lineNumber":150,"sourceCode":"    };\n    global.removeEventListener = function (\n      ...args: Parameters<typeof originalRemoveListener>\n    ) {\n      if (args[0] === 'error') {\n        userErrorListenerCount--;\n      }\n      return originalRemoveListener.apply(this, args);\n    };\n\n    if ('customExportConditions' in projectConfig.testEnvironmentOptions) {\n      const {customExportConditions} = projectConfig.testEnvironmentOptions;\n      if (\n        Array.isArray(customExportConditions) &&\n        customExportConditions.every(isString)\n      ) {\n        this._configuredExportConditions = customExportConditions;\n      } else {\n        throw new Error(\n          'Custom export conditions specified but they are not an array of strings',\n        );\n      }\n    }\n\n    this.moduleMocker = new ModuleMocker(global);\n\n    this.fakeTimers = new LegacyFakeTimers({\n      config: projectConfig,\n      global,\n      moduleMocker: this.moduleMocker,\n      timerConfig: {\n        idToRef: (id: number) => id,\n        refToId: (ref: number) => ref,\n      },\n    });\n\n    this.fakeTimersModern = new ModernFakeTimers({","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-environment-jsdom-abstract/src/index.ts#L132-L168","documentation":"Thrown by the JSDOM environment constructor when `testEnvironmentOptions.customExportConditions` is present but is not an array of strings. The validation checks `Array.isArray(...) && every(isString)`; if it fails, Jest cannot determine which package.json export conditions to use for module resolution.","triggerScenarios":"Setting `testEnvironmentOptions: { customExportConditions: 'browser' }` (string instead of array) or `{ customExportConditions: { browser: true } }` (object) or `{ customExportConditions: [123] }` (array with non-string elements) in jest.config.js or in a `@jest-environment-options` docblock.","commonSituations":"Confusing the type — writing a string or object instead of `['browser']`. Copy-pasting a config snippet from a blog that used the wrong type. Docblock override with malformed JSON.","solutions":["Set `customExportConditions` to an array of strings: `['browser']`.","If using docblock overrides, ensure valid JSON: `@jest-environment-options {\"customExportConditions\": [\"browser\"]}`.","Remove the option entirely if you want the default (`['browser']` for jsdom)."],"exampleFix":"// before\nmodule.exports = {\n  testEnvironment: 'jsdom',\n  testEnvironmentOptions: { customExportConditions: 'browser' },\n};\n\n// after\nmodule.exports = {\n  testEnvironment: 'jsdom',\n  testEnvironmentOptions: { customExportConditions: ['browser'] },\n};","handlingStrategy":"type-guard","validationCode":"// Validate customExportConditions type in config\nfunction validateExportConditions(opts) {\n  if ('customExportConditions' in opts) {\n    const c = opts.customExportConditions;\n    if (!Array.isArray(c) || !c.every(v => typeof v === 'string')) {\n      throw new TypeError('customExportConditions must be an array of strings');\n    }\n  }\n}","typeGuard":"function isStringArray(value: unknown): value is string[] {\n  return Array.isArray(value) && value.every(v => typeof v === 'string');\n}","tryCatchPattern":null,"preventionTips":["Always pass customExportConditions as an array of strings.","Use a JSON schema or config validation step in CI.","When using docblock overrides, validate the JSON with a linter."],"tags":["jest-environment-jsdom","configuration","export-conditions","validation"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}