{"record":{"id":"3fff8c9cc68d5077","repo":"denoland/deno","slug":"did-not-have-a-bin-property-with-a-string-or","errorCode":null,"errorMessage":"'{}' did not have a bin property with a string or non-empty object value","messagePattern":"'(.+?)' did not have a bin property with a string or non-empty object value","errorType":"exception","errorClass":"AnyError","httpStatus":null,"severity":"error","filePath":"libs/node_resolver/resolution.rs","lineNumber":2657,"sourceCode":"\n  // Search for...\n  // > \"$basedir/../next/dist/bin/next\" \"$@\"\n  // ...which is what it will look like on Windows\n  SCRIPT_PATH_RE\n    .captures(text)\n    .and_then(|c| c.get(1))\n    .map(|relative_path| {\n      file_path.parent().unwrap().join(relative_path.as_str())\n    })\n}\n\nfn resolve_bin_entry_value<'a>(\n  package_json: &PackageJson,\n  bins: &'a BTreeMap<String, BinValue>,\n  bin_name: Option<&str>,\n) -> Result<&'a BinValue, AnyError> {\n  if bins.is_empty() {\n    bail!(\n      \"'{}' did not have a bin property with a string or non-empty object value\",\n      package_json.path.display()\n    );\n  }\n  let default_bin = package_json.resolve_default_bin_name().ok();\n  let searching_bin = bin_name.or(default_bin);\n  match searching_bin.and_then(|bin_name| bins.get(bin_name)) {\n    Some(bin) => Ok(bin),\n    _ => {\n      if bins.len() > 1\n        && let Some(first) = bins.values().next()\n        && bins.values().all(|bin| bin == first)\n      {\n        return Ok(first);\n      }\n      if bin_name.is_none()\n        && bins.len() == 1\n        && let Some(first) = bins.values().next()","sourceCodeStart":2639,"sourceCodeEnd":2675,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/libs/node_resolver/resolution.rs#L2639-L2675","documentation":"When Deno resolves a package binary (running an `npm:` specifier as a command), `resolve_bin_entry_value` loads the package.json `bin` field into a map. If that map is empty — bin absent, an empty object, or otherwise unusable — it bails: the package declares no executable, so there is nothing for Deno to run.","triggerScenarios":"`deno run -A npm:<pkg>` (or resolving a bin out of a dependency) where the package's package.json has no `bin` field or `\"bin\": {}`. Typical with pure libraries invoked as if they were CLIs (e.g. `deno run -A npm:chalk`).","commonSituations":"Confusing an npm library with a CLI package; a package whose bin was removed in a newer major; monorepo packages that hoist their bin into a different sub-package; misspelled package names that resolve to a library.","solutions":["Check whether the package ships a CLI at all: `npm view <pkg> bin` — empty output means it is a library.","If it is a library, import it from code instead: `import lib from 'npm:<pkg>'` in a script, then `deno run script.ts`.","Run a specific exported file directly if the package exposes one: `deno run -A npm:<pkg>/<entry>.js`.","If you own the package, add a `\"bin\"` field mapping a name to an executable script."],"exampleFix":"# before\n$ deno run -A npm:chalk\n# error: '...node_modules/chalk/package.json' did not have a bin property with a string or non-empty object value\n\n# after: chalk is a library — import it instead\n# main.ts:  import chalk from 'npm:chalk@5';  console.log(chalk.green('ok'));\ndeno run -A main.ts","handlingStrategy":"validation","validationCode":"# confirm the package ships a bin before running it\nnpm view <pkg> bin   # empty/undefined => `deno run -A npm:<pkg>` will fail","typeGuard":"type PkgWithBin = { bin: string | Record<string, string> };\nfunction hasUsableBin(p: { bin?: unknown }): p is PkgWithBin {\n  if (typeof p.bin === \"string\") return p.bin.length > 0;\n  return typeof p.bin === \"object\" && p.bin !== null && Object.keys(p.bin).length > 0;\n}","tryCatchPattern":"const cmd = new Deno.Command(Deno.execPath(), { args: [\"run\", \"-A\", `npm:${pkg}`] });\nconst { stderr, success } = await cmd.output();\nif (!success && new TextDecoder().decode(stderr).includes(\"did not have a bin property\")) {\n  console.error(`${pkg} is a library (no bin) — import it from code instead of running it`);\n}","preventionTips":["Check `npm view <pkg> bin` before wiring `deno run -A npm:<pkg>` into scripts.","Prefer importing libraries and running your own entry file; reserve npm: execution for real CLIs.","When authoring packages, always declare a non-empty `bin` field for CLI entry points."],"tags":["npm","bin","package-json","node-compat","cli"],"backgroundTag":"package-bin-missing","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}