{"id":"bb00529bd69fe384","repo":"jestjs/jest","slug":"the-config-option-requires-a-json-string-literal","errorCode":null,"errorMessage":"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","messagePattern":"The --config option requires a JSON string literal, or a file path with one of these extensions: (.+?)\\.\nExample usage: jest --config \\./jest\\.config\\.js","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-cli/src/args.ts","lineNumber":85,"sourceCode":"    );\n  }\n\n  if (argv.ignoreProjects && argv.ignoreProjects.length === 0) {\n    throw new Error(\n      'The --ignoreProjects option requires the name of at least one project to be specified.\\n' +\n        'Example usage: jest --ignoreProjects my-first-project my-second-project',\n    );\n  }\n\n  if (\n    argv.config &&\n    !isJSONString(argv.config) &&\n    !new RegExp(\n      `\\\\.(${constants.JEST_CONFIG_EXT_ORDER.map(e => e.slice(1)).join('|')})$`,\n      'i',\n    ).test(argv.config)\n  ) {\n    throw new Error(\n      `The --config option requires a JSON string literal, or a file path with one of these extensions: ${constants.JEST_CONFIG_EXT_ORDER.join(\n        ', ',\n      )}.\\nExample usage: jest --config ./jest.config.js`,\n    );\n  }\n\n  return true;\n}\n\nexport const usage =\n  'Usage: $0 [--config=<pathToConfigFile>] [TestPathPatterns]';\nexport const docs = 'Documentation: https://jestjs.io/docs/cli';\n\n// The default values are all set in jest-config\nexport const options: {[key: string]: Options} = {\n  all: {\n    description:\n      'The opposite of `onlyChanged`. If `onlyChanged` is set by ' +","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-cli/src/args.ts#L67-L103","documentation":"`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.","triggerScenarios":"`jest --config ./config.yaml`, `jest --config jest-config.babel`, or `jest --config somefolder/` where the folder has no recognizable jest config file.","commonSituations":"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.","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."],"exampleFix":"# before\njest --config ./jest.yaml\n\n# after\njest --config ./jest.config.js","handlingStrategy":"validation","validationCode":"import {constants} from 'jest-config';\nconst CONFIG_EXT_RE = new RegExp(`\\\\.(${constants.JEST_CONFIG_EXT_ORDER.map(e => e.slice(1)).join('|')})$`, 'i');\nfunction validateConfigArg(cfg?: string): void {\n  if (cfg && !(cfg.trim().startsWith('{') || cfg.trim().startsWith('[')) && !CONFIG_EXT_RE.test(cfg)) {\n    throw new Error(`--config must be a JSON string or a path ending in one of: ${constants.JEST_CONFIG_EXT_ORDER.join(', ')}`);\n  }\n}","typeGuard":"const isConfigPath = (s: string) => /\\.(js|ts|mjs|mts|cjs|cts|json)$/i.test(s);\nconst isJsonString = (s: string) => s.trim().startsWith('{') || s.trim().startsWith('[');","tryCatchPattern":null,"preventionTips":["Prefer a jest.config.{js,ts} file over inline config.","If inlining, pass valid JSON.","Keep config in one of the supported extensions."],"tags":["jest-cli","cli-args","config","config-file"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}