{"id":"96ce0eb3805114c9","repo":"jestjs/jest","slug":"package-pkg-name-does-not-declare-jest-test","errorCode":null,"errorMessage":"Package '${pkg.name}' does not declare '@jest/test-utils' as dev dependency, but it is referenced in:\n\n${testUtilsReferences.join('\\n')}","messagePattern":"Package '(.+?)' does not declare '@jest/test-utils' as dev dependency, but it is referenced in:\n\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/buildTs.mjs","lineNumber":143,"sourceCode":"    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        )}`,\n      ),\n    );\n  }\n}\n\nconst args = [\n  'tsc',\n  '-b',\n  ...packagesWithTs.map(({packageDir}) => packageDir),\n  ...process.argv.slice(2),\n];\n","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/scripts/buildTs.mjs#L125-L161","documentation":"The inverse of 245: buildTs.mjs:142-152 fires when a package does NOT declare @jest/test-utils in devDependencies, yet one or more of its __tests__/tsconfig.json files reference a path ending in 'test-utils'. The build enforces a 1:1 correspondence between TS project references and the package.json devDependency declaration.","triggerScenarios":"Running scripts/buildTs.mjs after adding a `{ \"path\": \"...test-utils\" }` reference to a __tests__/tsconfig.json without also adding @jest/test-utils to that package's devDependencies.","commonSituations":"Copying a test tsconfig from another package that uses test-utils; adding a test that imports @jest/test-utils and wiring the TS reference but forgetting the package.json entry; workspace hooping masking the missing declaration locally.","solutions":["Add \"@jest/test-utils\" to the package's devDependencies (e.g. \"@jest/test-utils\": \"workspace:*\").","Alternatively, remove the stray test-utils reference from __tests__/tsconfig.json if test-utils isn't actually used.","Re-run scripts/buildTs.mjs to verify the reference/declaration pair is consistent."],"exampleFix":"// before: package.json has no @jest/test-utils, but __tests__/tsconfig.json references it\n// after (package.json)\n\"devDependencies\": { \"@jest/test-utils\": \"workspace:*\" }","handlingStrategy":"validation","validationCode":"function assertNoDanglingTestUtilsReference(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}: test-utils referenced in tsconfig but not in devDependencies`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Any time you add a `references` entry ending in 'test-utils', also add @jest/test-utils to devDependencies.","When copying a __tests__/tsconfig.json from another package, prune references you don't need.","Treat the devDependency declaration and the tsconfig reference as a single atomic change."],"tags":["build","monorepo","typescript","tsconfig","references","test-utils","package-json"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}