{"id":"c4529b4ee4cdf326","repo":"jestjs/jest","slug":"binary-in-package-pkg-name-with-name-binna","errorCode":null,"errorMessage":"Binary in package \"${pkg.name}\" with name \"${binName}\" at ${binPath} does not exist","messagePattern":"Binary in package \"(.+?)\" with name \"(.+?)\" at (.+?) does not exist","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/buildUtils.mjs","lineNumber":125,"sourceCode":"      assert.strictEqual(\n        pkg.types,\n        './build/index.d.ts',\n        `Package \"${pkg.name}\" should have \"./build/index.d.ts\" as types`,\n      );\n    } else {\n      assert.strictEqual(\n        pkg.main,\n        './index.js',\n        `Package \"${pkg.name}\" should have \"./index.js\" as main`,\n      );\n    }\n\n    if (pkg.bin) {\n      for (const [binName, binPath] of Object.entries(pkg.bin)) {\n        const fullBinPath = path.resolve(packageDir, binPath);\n\n        if (!fs.existsSync(fullBinPath)) {\n          throw new Error(\n            `Binary in package \"${pkg.name}\" with name \"${binName}\" at ${binPath} does not exist`,\n          );\n        }\n      }\n    }\n\n    return {packageDir, pkg};\n  });\n}\n\nexport function getPackagesWithTsConfig() {\n  return getPackages().filter(p =>\n    fs.existsSync(path.resolve(p.packageDir, 'tsconfig.json')),\n  );\n}\n\nexport const INLINE_REQUIRE_EXCLUDE_LIST =\n  /packages\\/expect|(jest-(circus|diff|get-type|jasmine2|matcher-utils|message-util|regex-util|snapshot))|pretty-format\\//;","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/scripts/buildUtils.mjs#L107-L143","documentation":"buildUtils.mjs getPackages() validates each package.json; for packages with a `bin` field it iterates each {binName, binPath} and resolves the path against the package directory. At buildUtils.mjs:124, if the resolved bin file does not exist on disk, it throws. This catches declared CLI entry points that are missing before the package can be built/published.","triggerScenarios":"Running the build utility (getPackages is called by build.mjs/buildTs.mjs) for a package whose package.json `bin` points at a path that hasn't been built or was renamed — e.g. \"bin\": { \"jest\": \"./bin/jest.js\" } when ./bin/jest.js does not exist.","commonSituations":"Declaring a bin entry before creating the file; renaming the bin script but not the package.json field; the bin target living in a build output dir that hasn't been generated yet at validation time; relative path typos.","solutions":["Create the bin file at the declared path, or correct the path in package.json `bin` to point where the file actually lives.","Ensure any build step that generates the bin file runs before getPackages()/buildUtils validation.","Confirm the path is relative to the package directory (it is resolved via path.resolve(packageDir, binPath))."],"exampleFix":"// before (package.json)\n\"bin\": { \"mycli\": \"./cli.js\" }\n// (./cli.js missing; actual file is ./bin/cli.js)\n// after\n\"bin\": { \"mycli\": \"./bin/cli.js\" }","handlingStrategy":"validation","validationCode":"const fs = require('fs'), path = require('path');\nfunction assertBinFilesExist(pkg, packageDir) {\n  if (!pkg.bin) return;\n  for (const [name, rel] of Object.entries(pkg.bin)) {\n    const full = path.resolve(packageDir, rel);\n    if (!fs.existsSync(full)) {\n      throw new Error(`Binary '${name}' at ${rel} missing for ${pkg.name}`);\n    }\n  }\n}","typeGuard":"function binsExist(pkg, packageDir) {\n  if (!pkg.bin) return true;\n  return Object.values(pkg.bin).every(rel => fs.existsSync(path.resolve(packageDir, rel)));\n}","tryCatchPattern":null,"preventionTips":["Create the bin file in the same commit that declares it in package.json.","Keep bin paths relative to the package directory and verify them after renames.","If the bin is a build output, ensure the build runs before the bin-existence validation step."],"tags":["build","package-json","bin","cli","monorepo"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}