jestjs/jest · error · Error
The --config option requires a JSON string literal, or a fil
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` throws (packages/jest-cli/src/args.ts:77) when `--config` is neither a JSON string nor a path ending in one of the recognized config extensions (.js, .ts, .mjs, .mts, .cjs, .cts, .json — see JEST_CONFIG_EXT_ORDER in jest-config/constants.ts). This stops Jest from silently treating an arbitrary file as a config.
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 f49721c78e)
Solutions
- Rename/author your config with a supported extension, e.g. `jest.config.js` or `jest.config.ts`.
- If you need to pass config inline, pass a JSON object string: `jest --config '{"testMatch":["**/*.test.js"]}'`.
- Point `--config` at the directory containing a valid `jest.config.*` file rather than an unrelated file.
Example fix
# before jest --config ./jest.yaml # after jest --config ./jest.config.js
Defensive patterns
Strategy: validation
Validate before calling
import {constants} from 'jest-config';
const CONFIG_EXT_RE = new RegExp(`\\.(${constants.JEST_CONFIG_EXT_ORDER.map(e => e.slice(1)).join('|')})$`, 'i');
function validateConfigArg(cfg?: string): void {
if (cfg && !(cfg.trim().startsWith('{') || cfg.trim().startsWith('[')) && !CONFIG_EXT_RE.test(cfg)) {
throw new Error(`--config must be a JSON string or a path ending in one of: ${constants.JEST_CONFIG_EXT_ORDER.join(', ')}`);
}
} Type guard
const isConfigPath = (s: string) => /\.(js|ts|mjs|mts|cjs|cts|json)$/i.test(s);
const isJsonString = (s: string) => s.trim().startsWith('{') || s.trim().startsWith('['); Prevention
- Prefer a jest.config.{js,ts} file over inline config.
- If inlining, pass valid JSON.
- Keep config in one of the supported extensions.
When it happens
Trigger: `jest --config ./config.yaml`, `jest --config jest-config.babel`, or `jest --config somefolder/` where the folder has no recognizable jest config file.
Common situations: Pointing at a YAML/TOML config (Jest has no native YAML loader), a typo in the filename, or a config written in an unsupported extension.
Related errors
- Both --runInBand and --maxWorkers were specified, only one i
- Both --${key} and --watchAll were specified, but cannot be u
- Both --onlyFailures and --watchAll were specified, only one
- The --findRelatedTests option requires file paths to be spec
- The --maxWorkers (-w) option requires a number or string to
AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03).
Data as JSON: /data/errors/bb00529bd69fe384.json.
Report an issue: GitHub.