{"id":"a09a7dbfb3f1101b","repo":"jestjs/jest","slug":"file-has-the-following-non-node-type-references","errorCode":null,"errorMessage":"${file} has the following non-node type references:\n\n${references}","messagePattern":"(.+?) has the following non-node type references:\n\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/buildTs.mjs","lineNumber":226,"sourceCode":"              .split('\\n')\n              .map(line => line.trim())\n              .filter(line => line.includes(typesReferenceDirective))\n              .filter(line => line !== typesNodeReferenceDirective)\n              .join('\\n'),\n          ])\n          .filter(([, content]) => content.length > 0)\n          .filter(hit => hit.length > 0)\n          .map(([file, references]) =>\n            chalk.red(\n              `${chalk.bold(\n                file,\n              )} has the following non-node type references:\\n\\n${references}\\n`,\n            ),\n          )\n          .join('\\n\\n');\n\n        if (filesWithReferences) {\n          throw new Error(filesWithReferences);\n        }\n\n        const filesWithNodeReference = filesWithTypeReferences.map(\n          ([filename]) => filename,\n        );\n\n        if (filesWithNodeReference.length > 0) {\n          assert.ok(\n            pkg.dependencies,\n            `Package \\`${pkg.name}\\` is missing \\`dependencies\\``,\n          );\n          assert.strictEqual(\n            pkg.dependencies['@types/node'],\n            '*',\n            `Package \\`${pkg.name}\\` is missing a dependency on \\`@types/node\\``,\n          );\n        }\n      }),","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/scripts/buildTs.mjs#L208-L244","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before (src/foo.ts)\n/// <reference types=\"lodash\" />\nimport lodash from 'lodash';\n// after\nimport lodash from 'lodash';","handlingStrategy":"validation","validationCode":"const fs = require('fs'), path = require('path');\nfunction findNonNodeTypeReferences(buildDir) {\n  const files = globSync('**/*.d.ts', { cwd: buildDir, absolute: true });\n  const offenders = [];\n  for (const f of files) {\n    const lines = fs.readFileSync(f, 'utf8').split('\\n').map(l => l.trim());\n    const bad = lines.filter(l => l.includes('/// <reference types') && l !== '/// <reference types=\"node\" />');\n    if (bad.length) offenders.push({ file: f, refs: bad });\n  }\n  return offenders;\n}","typeGuard":"function hasOnlyNodeReferenceTypes(content): boolean {\n  return content.split('\\n').map(l => l.trim())\n    .filter(l => l.includes('/// <reference types'))\n    .every(l => l === '/// <reference types=\"node\" />');\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["build","typescript","declaration-files","dts","triple-slash","monorepo"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}