jestjs/jest · error · Error

The --config option requires a JSON string literal, or a…

Error message

The --config option requires a JSON string literal, or a file path with one of these extensions: ${constants.JEST_CONFIG_EXT_ORDER.join(', ')}.
Example usage: jest --config ./jest.config.js

What it means

check() validates that --config be either a parseable JSON string or a file path ending in one of Jest's recognized config extensions (args.ts:77-90). JEST_CONFIG_EXT_ORDER covers .ts/.js/.mjs/.cjs/.json/.mts/.cts variants. A value that is neither JSON nor a matching file extension is rejected because Jest would not know how to load it.

Solutions

  1. Use a recognized extension: jest --config ./jest.config.js (or .ts/.mjs/.cjs/.json/.mts/.cts).
  2. If you want inline config, pass a valid JSON string: jest --config '{"testMatch":["**/*.test.js"]}'.
  3. Rename or symlink your config file to a supported extension.

Example fix

// before
jest --config ./jest.config
// after
jest --config ./jest.config.js
Defensive patterns

Strategy: validation

Validate before calling

import { constants } from 'jest-config';
const EXT_RE = new RegExp(`\\.(${constants.JEST_CONFIG_EXT_ORDER.map(e => e.slice(1)).join('|')})$`, 'i');
function validateConfigArg(cfg: string): void {
  let isJson = false;
  try { JSON.parse(cfg); isJson = true; } catch {}
  if (!isJson && !EXT_RE.test(cfg)) {
    throw new Error('--config must be JSON or a supported extension path');
  }
}

Type guard

function isJsonOrConfigPath(cfg: string): boolean {
  let json = false;
  try { JSON.parse(cfg); json = true; } catch {}
  return json || /\.(ts|js|mjs|cjs|json|mts|cts)$/i.test(cfg);
}

Prevention

When it happens

Trigger: Running jest --config ./jest.config (no extension); jest --config ./config.yaml; jest --config {broken json}; jest --config somefile.txt.

Common situations: Renaming a config to a non-standard extension; pointing at a YAML/TOML file Jest can't natively load; a typo in the path; passing a JS module path that lacks the .js/.ts suffix.

Related errors


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

Appendix: source

Thrown at packages/jest-cli/src/args.ts:85

    );
  }

  if (argv.ignoreProjects && argv.ignoreProjects.length === 0) {
    throw new Error(
      'The --ignoreProjects option requires the name of at least one project to be specified.\n' +
        'Example usage: jest --ignoreProjects my-first-project my-second-project',
    );
  }

  if (
    argv.config &&
    !isJSONString(argv.config) &&
    !new RegExp(
      `\\.(${constants.JEST_CONFIG_EXT_ORDER.map(e => e.slice(1)).join('|')})$`,
      'i',
    ).test(argv.config)
  ) {
    throw new Error(
      `The --config option requires a JSON string literal, or a file path with one of these extensions: ${constants.JEST_CONFIG_EXT_ORDER.join(
        ', ',
      )}.\nExample usage: jest --config ./jest.config.js`,
    );
  }

  return true;
}

export const usage =
  'Usage: $0 [--config=<pathToConfigFile>] [TestPathPatterns]';
export const docs = 'Documentation: https://jestjs.io/docs/cli';

// The default values are all set in jest-config
export const options: {[key: string]: Options} = {
  all: {
    description:
      'The opposite of `onlyChanged`. If `onlyChanged` is set by ' +

View on GitHub (pinned to 8e6d128e4a)