jestjs/jest · error · Error

Binary in package "${pkg.name}" with name "${binName}" at ${

Error message

Binary in package "${pkg.name}" with name "${binName}" at ${binPath} does not exist

What it means

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.

Source

Thrown at scripts/buildUtils.mjs:125

      assert.strictEqual(
        pkg.types,
        './build/index.d.ts',
        `Package "${pkg.name}" should have "./build/index.d.ts" as types`,
      );
    } else {
      assert.strictEqual(
        pkg.main,
        './index.js',
        `Package "${pkg.name}" should have "./index.js" as main`,
      );
    }

    if (pkg.bin) {
      for (const [binName, binPath] of Object.entries(pkg.bin)) {
        const fullBinPath = path.resolve(packageDir, binPath);

        if (!fs.existsSync(fullBinPath)) {
          throw new Error(
            `Binary in package "${pkg.name}" with name "${binName}" at ${binPath} does not exist`,
          );
        }
      }
    }

    return {packageDir, pkg};
  });
}

export function getPackagesWithTsConfig() {
  return getPackages().filter(p =>
    fs.existsSync(path.resolve(p.packageDir, 'tsconfig.json')),
  );
}

export const INLINE_REQUIRE_EXCLUDE_LIST =
  /packages\/expect|(jest-(circus|diff|get-type|jasmine2|matcher-utils|message-util|regex-util|snapshot))|pretty-format\//;

View on GitHub (pinned to f49721c78e)

Solutions

  1. Create the bin file at the declared path, or correct the path in package.json `bin` to point where the file actually lives.
  2. Ensure any build step that generates the bin file runs before getPackages()/buildUtils validation.
  3. Confirm the path is relative to the package directory (it is resolved via path.resolve(packageDir, binPath)).

Example fix

// before (package.json)
"bin": { "mycli": "./cli.js" }
// (./cli.js missing; actual file is ./bin/cli.js)
// after
"bin": { "mycli": "./bin/cli.js" }
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs'), path = require('path');
function assertBinFilesExist(pkg, packageDir) {
  if (!pkg.bin) return;
  for (const [name, rel] of Object.entries(pkg.bin)) {
    const full = path.resolve(packageDir, rel);
    if (!fs.existsSync(full)) {
      throw new Error(`Binary '${name}' at ${rel} missing for ${pkg.name}`);
    }
  }
}

Type guard

function binsExist(pkg, packageDir) {
  if (!pkg.bin) return true;
  return Object.values(pkg.bin).every(rel => fs.existsSync(path.resolve(packageDir, rel)));
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03). Data as JSON: /data/errors/c4529b4ee4cdf326.json. Report an issue: GitHub.