denoland/deno · error · TypeError

Unexpected second argument to Deno.bench()

Error message

Unexpected second argument to Deno.bench()

What it means

In the compiled-binary install path of `deno install -g <url>`, deno resolves the output directory (same `get_installer_bin_dir` logic: `$DENO_INSTALL_ROOT/bin`, default `~/.deno/bin`, or `--root`), verifies existing metadata is a directory, or creates the directory tree when missing. If the path exists but is a file, it aborts before compiling.

Solutions

  1. Inspect the path: `ls -la "$DENO_INSTALL_ROOT"` and check whether a file sits where the `bin` directory should be
  2. Fix `DENO_INSTALL_ROOT` to a directory (deno creates `<root>/bin` automatically if missing)
  3. Delete or move the stray file and re-run the install
  4. Pass `--root <dir>` pointing at the intended install root

Example fix

# before
$ DENO_INSTALL_ROOT=~/tools.txt deno install -g https://example.com/cli.ts
# Installation path is not a directory

# after
$ DENO_INSTALL_ROOT=~/tools deno install -g https://example.com/cli.ts  # ok
Defensive patterns

Strategy: validation

Validate before calling

# Ensure the target dir is creatable/is a directory before global install
BIN_DIR="${DENO_INSTALL_ROOT:-$HOME/.deno}"
BIN_DIR="${BIN_DIR%/bin}/bin"
mkdir -p "$BIN_DIR" && [ -d "$BIN_DIR" ] && deno install -g "$URL"

Prevention

When it happens

Trigger: `deno install -g <module-url>` (or with `--root`) when the resolved install dir path is occupied by a regular file: `DENO_INSTALL_ROOT` misconfigured to a file path, or a file named `bin` inside the root directory.

Common situations: Bad `DENO_INSTALL_ROOT` in CI or container images; `--root` pointing at a file; leftover artifacts from previous experiments occupying the path.

Related errors


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

Appendix: source

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

      }
      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) {
        throw new TypeError(
          "Unexpected 'fn' field in options, bench function is already provided as the second argument",
        );

View on GitHub (pinned to 9ad36f7a2c)