{"id":"c3c5d4c5f3682349","repo":"jestjs/jest","slug":"package-pkg-name-declares-jest-test-utils-c3c5d4","errorCode":null,"errorMessage":"Package '${pkg.name}' declares '@jest/test-utils' as dev dependency, but it is not referenced in:\n\n${tsConfigPaths.join('\\n')}","messagePattern":"Package '(.+?)' declares '@jest/test-utils' as dev dependency, but it is not referenced in:\n\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/buildTs.mjs","lineNumber":131,"sourceCode":"  );\n\n  const tsConfigPaths = glob.sync('**/__tests__/tsconfig.json', {\n    absolute: true,\n    cwd: packageDir,\n  });\n\n  const testUtilsReferences = tsConfigPaths.filter(tsConfigPath => {\n    const tsConfig = JSON.parse(\n      stripJsonComments(fs.readFileSync(tsConfigPath, 'utf8')),\n    );\n\n    return tsConfig.references.some(\n      ({path}) => path && path.endsWith('test-utils'),\n    );\n  });\n\n  if (hasJestTestUtils && testUtilsReferences.length === 0) {\n    throw new Error(\n      chalk.red(\n        `Package '${\n          pkg.name\n        }' declares '@jest/test-utils' as dev dependency, but it is not referenced in:\\n\\n${tsConfigPaths.join(\n          '\\n',\n        )}`,\n      ),\n    );\n  }\n\n  if (!hasJestTestUtils && testUtilsReferences.length > 0) {\n    throw new Error(\n      chalk.red(\n        `Package '${\n          pkg.name\n        }' does not declare '@jest/test-utils' as dev dependency, but it is referenced in:\\n\\n${testUtilsReferences.join(\n          '\\n',\n        )}`,","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/scripts/buildTs.mjs#L113-L149","documentation":"After confirming @jest/test-utils is correctly in devDependencies, buildTs.mjs:115-140 globs each package's __tests__/tsconfig.json files and checks whether any references a path ending in 'test-utils'. If the package declares the devDependency but NO test tsconfig references it, the declaration is dead weight and the script throws. It enforces that a declared test-utils devDep is actually wired into the TS project references.","triggerScenarios":"Running scripts/buildTs.mjs when a package lists @jest/test-utils in devDependencies but none of its __tests__/tsconfig.json files contain a `references` entry pointing to the test-utils path.","commonSituations":"Adding @jest/test-utils to devDependencies preemptively before writing tests that use it; renaming/moving the test-utils reference so the `endsWith('test-utils')` check no longer matches; removing the tests but leaving the devDep.","solutions":["Add a project reference to test-utils in the relevant __tests__/tsconfig.json, e.g. { \"references\": [{ \"path\": \"../../test-utils\" }] }.","If the package no longer uses @jest/test-utils, remove it from devDependencies instead (note error 246 enforces the inverse).","Ensure the reference path string ends with 'test-utils' so the matcher at buildTs.mjs:126 fires."],"exampleFix":"// before (packages/foo/__tests__/tsconfig.json)\n{ \"references\": [] }\n// after\n{ \"references\": [{ \"path\": \"../../test-utils\" }] }","handlingStrategy":"validation","validationCode":"function assertTestUtilsReferenceExists(pkg, packageDir, glob, fs, stripJsonComments) {\n  const isDevDep = Object.keys(pkg.devDependencies || {}).includes('@jest/test-utils');\n  const tsConfigs = glob.sync('**/__tests__/tsconfig.json', { absolute: true, cwd: packageDir });\n  const refs = tsConfigs.filter(p => {\n    const cfg = JSON.parse(stripJsonComments(fs.readFileSync(p, 'utf8')));\n    return (cfg.references || []).some(r => r.path && r.path.endsWith('test-utils'));\n  });\n  if (isDevDep && refs.length === 0) {\n    throw new Error(`${pkg.name}: @jest/test-utils declared but not referenced in any __tests__/tsconfig.json`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When adding @jest/test-utils to devDependencies, immediately add a matching reference in the relevant __tests__/tsconfig.json.","Keep the reference path ending in 'test-utils' so the build's matcher recognizes it.","If you stop using test-utils, remove both the devDependency and the tsconfig reference together."],"tags":["build","monorepo","typescript","tsconfig","references","test-utils"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}