{"id":"443f73b6c86e855a","repo":"jestjs/jest","slug":"jest-you-can-only-define-a-single-loader-through","errorCode":null,"errorMessage":"Jest: You can only define a single loader through docblocks, got \"${tsLoader.join(', ')}\"","messagePattern":"Jest: You can only define a single loader through docblocks, got \"(.+?)\"","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/jest-config/src/readConfigFileAndSetRootDir.ts","lineNumber":162,"sourceCode":"\nconst loadDocblockPragmasInConfig = (configPath: string): Pragmas => {\n  const docblockPragmas = parse(extract(fs.readFileSync(configPath, 'utf8')));\n  return docblockPragmas;\n};\n\nconst loadTSConfigFile = async (\n  configPath: string,\n): Promise<Config.InitialOptions> => {\n  // Get registered TypeScript compiler instance\n  const docblockPragmas = loadDocblockPragmasInConfig(configPath);\n  const tsLoader = docblockPragmas['jest-config-loader'] || 'ts-node';\n  const docblockTSLoaderOptions = docblockPragmas['jest-config-loader-options'];\n\n  if (typeof docblockTSLoaderOptions === 'string') {\n    extraTSLoaderOptions = JSON.parse(docblockTSLoaderOptions);\n  }\n  if (Array.isArray(tsLoader)) {\n    throw new TypeError(\n      `Jest: You can only define a single loader through docblocks, got \"${tsLoader.join(\n        ', ',\n      )}\"`,\n    );\n  }\n\n  const registeredCompiler = await getRegisteredCompiler(\n    tsLoader as TsLoaderModule,\n  );\n  registeredCompiler.enabled(true);\n\n  let configObject = interopRequireDefault(require(configPath)).default;\n\n  // In case the config is a function which imports more Typescript code\n  if (typeof configObject === 'function') {\n    configObject = await configObject();\n  }\n","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-config/src/readConfigFileAndSetRootDir.ts#L144-L180","documentation":"When loading a TS config via a loader, Jest reads the `@jest-config-loader` pragma from the docblock at the top of the config file. The pragma must name exactly one loader ('ts-node' or 'esbuild-register'). If the docblock contains the pragma twice, jest-docblock returns an array, and this TypeError is thrown.","triggerScenarios":"Writing `@jest-config-loader ts-node` and `@jest-config-loader esbuild-register` in the same docblock header of jest.config.ts.","commonSituations":"Copy-pasting a docblock from two sources; merging config snippets without deduplicating pragmas.","solutions":["Keep only one @jest-config-loader line in the docblock","Remove the docblock entirely to use the default 'ts-node' loader"],"exampleFix":"/**\n * @jest-config-loader ts-node\n * @jest-config-loader esbuild-register\n */\n// becomes\n/**\n * @jest-config-loader ts-node\n */","handlingStrategy":"validation","validationCode":"import {parse, extract} from 'jest-docblock';\nimport * as fs from 'node:fs';\nconst pragmas = parse(extract(fs.readFileSync('jest.config.ts', 'utf8')));\nconst loader = pragmas['jest-config-loader'];\nif (Array.isArray(loader)) {\n  throw new Error('Multiple @jest-config-loader pragmas detected');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Lint docblock pragmas to forbid duplicates","Maintain a single source config docblock template"],"tags":["typescript","config","docblock","loader"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}