jestjs/jest · error · Error
${file} has the following non-node type references: ${refer
Error message
${file} has the following non-node type references:
${references} What it means
After tsc emits .d.ts files, buildTs.mjs:200-227 scans every build/**/*.d.ts for `/// <reference types="..." />` directives. Only `/// <reference types="node" />` is permitted (allowed via typesNodeReferenceDirective); any other bundled type reference is reported and, if any exist, the script throws at buildTs.mjs:226. Bundled declarations must be self-contained so consumers don't need to install transitive @types packages.
Source
Thrown at scripts/buildTs.mjs:226
.split('\n')
.map(line => line.trim())
.filter(line => line.includes(typesReferenceDirective))
.filter(line => line !== typesNodeReferenceDirective)
.join('\n'),
])
.filter(([, content]) => content.length > 0)
.filter(hit => hit.length > 0)
.map(([file, references]) =>
chalk.red(
`${chalk.bold(
file,
)} has the following non-node type references:\n\n${references}\n`,
),
)
.join('\n\n');
if (filesWithReferences) {
throw new Error(filesWithReferences);
}
const filesWithNodeReference = filesWithTypeReferences.map(
([filename]) => filename,
);
if (filesWithNodeReference.length > 0) {
assert.ok(
pkg.dependencies,
`Package \`${pkg.name}\` is missing \`dependencies\``,
);
assert.strictEqual(
pkg.dependencies['@types/node'],
'*',
`Package \`${pkg.name}\` is missing a dependency on \`@types/node\``,
);
}
}),View on GitHub (pinned to f49721c78e)
Solutions
- Remove the non-node `/// <reference types="..." />` directive from the source file and use a normal import instead.
- If the directive comes from a transitive @types package, avoid importing types from it in the public surface, or inline/extract the needed types.
- Rebuild and re-run scripts/buildTs.mjs; the scan must find only node references (or none).
Example fix
// before (src/foo.ts) /// <reference types="lodash" /> import lodash from 'lodash'; // after import lodash from 'lodash';
Defensive patterns
Strategy: validation
Validate before calling
const fs = require('fs'), path = require('path');
function findNonNodeTypeReferences(buildDir) {
const files = globSync('**/*.d.ts', { cwd: buildDir, absolute: true });
const offenders = [];
for (const f of files) {
const lines = fs.readFileSync(f, 'utf8').split('\n').map(l => l.trim());
const bad = lines.filter(l => l.includes('/// <reference types') && l !== '/// <reference types="node" />');
if (bad.length) offenders.push({ file: f, refs: bad });
}
return offenders;
} Type guard
function hasOnlyNodeReferenceTypes(content): boolean {
return content.split('\n').map(l => l.trim())
.filter(l => l.includes('/// <reference types'))
.every(l => l === '/// <reference types="node" />');
} Prevention
- Avoid `/// <reference types="..." />` in source; prefer normal imports so tsc tracks types explicitly.
- If a transitive @types package injects a reference directive, avoid re-exporting its types from your public surface.
- Run scripts/buildTs.mjs locally before pushing so leaked directives surface early.
When it happens
Trigger: A source file contains `/// <reference types="some-package" />` (other than node), or imports a type whose @types package injects a reference directive that tsc copies into the emitted .d.ts. Running scripts/buildTs.mjs then surfaces the offending file(s) and their reference lines.
Common situations: Adding a dependency on a third-party package with bundled @types that emit reference directives; hand-writing triple-slash reference directives in source instead of normal imports; an @types package whose auto-generated directive leaks into the public .d.ts surface.
Related errors
- API Extractor completed with ${extractorResult.errorCount} e
- Package '${pkg.name}' declares '@jest/test-utils' as dev dep
- Package '${pkg.name}' does not declare '@jest/test-utils' as
- No exports found in package ${pkg.name}
- Package '${pkg.name}' declares '@jest/test-utils' as depende
AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03).
Data as JSON: /data/errors/a09a7dbfb3f1101b.json.
Report an issue: GitHub.