{"record":{"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":"exception","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/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-cli/src/args.ts#L67-L103","documentation":"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.","triggerScenarios":"Running jest --config ./jest.config (no extension); jest --config ./config.yaml; jest --config {broken json}; jest --config somefile.txt.","commonSituations":"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.","solutions":["Use a recognized extension: jest --config ./jest.config.js (or .ts/.mjs/.cjs/.json/.mts/.cts).","If you want inline config, pass a valid JSON string: jest --config '{\"testMatch\":[\"**/*.test.js\"]}'.","Rename or symlink your config file to a supported extension."],"exampleFix":"// before\njest --config ./jest.config\n// after\njest --config ./jest.config.js","handlingStrategy":"validation","validationCode":"import { constants } from 'jest-config';\nconst EXT_RE = new RegExp(`\\\\.(${constants.JEST_CONFIG_EXT_ORDER.map(e => e.slice(1)).join('|')})$`, 'i');\nfunction validateConfigArg(cfg: string): void {\n  let isJson = false;\n  try { JSON.parse(cfg); isJson = true; } catch {}\n  if (!isJson && !EXT_RE.test(cfg)) {\n    throw new Error('--config must be JSON or a supported extension path');\n  }\n}","typeGuard":"function isJsonOrConfigPath(cfg: string): boolean {\n  let json = false;\n  try { JSON.parse(cfg); json = true; } catch {}\n  return json || /\\.(ts|js|mjs|cjs|json|mts|cts)$/i.test(cfg);\n}","tryCatchPattern":null,"preventionTips":["Standardize on jest.config.{ts,js} files rather than inline JSON strings.","Keep a single canonical config location and reference it by path.","Avoid non-standard extensions (yaml/toml) unless you add a custom loader."],"tags":["jest-cli","cli-args","config","file-extension","json"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}