jestjs/jest · error · Error
Package '${pkg.name}' declares '@jest/test-utils' as dev dep
Error message
Package '${pkg.name}' declares '@jest/test-utils' as dev dependency, but it is not referenced in:
${tsConfigPaths.join('\n')} What it means
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.
Source
Thrown at scripts/buildTs.mjs:131
);
const tsConfigPaths = glob.sync('**/__tests__/tsconfig.json', {
absolute: true,
cwd: packageDir,
});
const testUtilsReferences = tsConfigPaths.filter(tsConfigPath => {
const tsConfig = JSON.parse(
stripJsonComments(fs.readFileSync(tsConfigPath, 'utf8')),
);
return tsConfig.references.some(
({path}) => path && path.endsWith('test-utils'),
);
});
if (hasJestTestUtils && testUtilsReferences.length === 0) {
throw new Error(
chalk.red(
`Package '${
pkg.name
}' declares '@jest/test-utils' as dev dependency, but it is not referenced in:\n\n${tsConfigPaths.join(
'\n',
)}`,
),
);
}
if (!hasJestTestUtils && testUtilsReferences.length > 0) {
throw new Error(
chalk.red(
`Package '${
pkg.name
}' does not declare '@jest/test-utils' as dev dependency, but it is referenced in:\n\n${testUtilsReferences.join(
'\n',
)}`,View on GitHub (pinned to f49721c78e)
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.
Example fix
// before (packages/foo/__tests__/tsconfig.json)
{ "references": [] }
// after
{ "references": [{ "path": "../../test-utils" }] } Defensive patterns
Strategy: validation
Validate before calling
function assertTestUtilsReferenceExists(pkg, packageDir, glob, fs, stripJsonComments) {
const isDevDep = Object.keys(pkg.devDependencies || {}).includes('@jest/test-utils');
const tsConfigs = glob.sync('**/__tests__/tsconfig.json', { absolute: true, cwd: packageDir });
const refs = tsConfigs.filter(p => {
const cfg = JSON.parse(stripJsonComments(fs.readFileSync(p, 'utf8')));
return (cfg.references || []).some(r => r.path && r.path.endsWith('test-utils'));
});
if (isDevDep && refs.length === 0) {
throw new Error(`${pkg.name}: @jest/test-utils declared but not referenced in any __tests__/tsconfig.json`);
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Package '${pkg.name}' does not declare '@jest/test-utils' as
- Package '${pkg.name}' declares '@jest/test-utils' as depende
- ${file} has the following non-node type references: ${refer
- API Extractor completed with ${extractorResult.errorCount} e
- No exports found in package ${pkg.name}
AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03).
Data as JSON: /data/errors/c3c5d4c5f3682349.json.
Report an issue: GitHub.