denoland/deno · error · TypeError

The bench function must have a name

Error message

The bench function must have a name

What it means

During `deno uninstall <name>`, deno builds `<bin_dir>/<name>` (plus `<name>.cmd`/`<name>.exe` on Windows) and calls `remove_file_if_exists` for each. If none of those files existed, nothing was removed and deno aborts with this error rather than reporting success on a no-op. It also then cleans up legacy `<name>.tsconfig.json` / `<name>.deno.json` / `<name>.lock.json` siblings, but only after a successful removal.

Solutions

  1. List what is actually installed: `ls ~/.deno/bin` (or `ls "$DENO_INSTALL_ROOT/bin"`)
  2. Re-run uninstall with the exact shim filename found there (omit extension on Windows)
  3. If a custom root was used at install time, pass the same `--root <dir>`
  4. If nothing relevant exists, the uninstall goal is already met — ignore or script around it

Example fix

# before
$ deno uninstall @foo/cli
# No installation found for @foo/cli

# after
$ ls ~/.deno/bin
foobar*
$ deno uninstall foobar  # removed
Defensive patterns

Strategy: validation

Validate before calling

# Check the shim exists before attempting uninstall
BIN_DIR="${DENO_INSTALL_ROOT:-$HOME/.deno}/bin"
command -v "$BIN_DIR/$PKG" >/dev/null 2>&1 || ls "$BIN_DIR" | grep -i "$PKG"

Try / catch

In automation scripts, call `deno uninstall <name>` and on failure match /No installation found/ — treat it as already-clean (exit 0) instead of failing the pipeline; any other stderr should fail loudly.

Prevention

When it happens

Trigger: `deno uninstall cowsay` when no `cowsay` executable exists in the resolved bin dir: the name is misspelled, the package was installed under a different (possibly inferred) bin name, or the install root used now differs from the one used at install time (`DENO_INSTALL_ROOT` changed, `--root` not passed).

Common situations: Typo in the package/binary name; the installed shim name came from the package's `bin` map (e.g. package `@foo/cli` installs shim `foobar`) and the user uninstalls the package name instead; `DENO_INSTALL_ROOT` differs between the installing shell and the current shell; the tool was already uninstalled.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/41fe776b3e179452. Report an issue: GitHub.

Appendix: source

Thrown at cli/js/40_bench.js:143

        throw new TypeError(
          "Unexpected 'fn' field in options, bench function is already provided as the third argument",
        );
      }
      if (optionsOrFn.name != undefined) {
        throw new TypeError(
          "Unexpected 'name' field in options, bench name is already provided as the first argument",
        );
      }
      benchDesc = {
        ...defaults,
        ...optionsOrFn,
        fn: maybeFn,
        name: nameOrFnOrOptions,
      };
    }
  } else if (typeof nameOrFnOrOptions === "function") {
    if (!nameOrFnOrOptions.name) {
      throw new TypeError("The bench function must have a name");
    }
    if (optionsOrFn != undefined) {
      throw new TypeError("Unexpected second argument to Deno.bench()");
    }
    if (maybeFn != undefined) {
      throw new TypeError("Unexpected third argument to Deno.bench()");
    }
    benchDesc = {
      ...defaults,
      fn: nameOrFnOrOptions,
      name: nameOrFnOrOptions.name,
    };
  } else {
    let fn;
    let name;
    if (typeof optionsOrFn === "function") {
      fn = optionsOrFn;
      if (nameOrFnOrOptions.fn != undefined) {

View on GitHub (pinned to 9ad36f7a2c)