denoland/deno · error · TypeError
Expected 'fn' field in the first argument to be a bench…
Error message
Expected 'fn' field in the first argument to be a bench function
What it means
In the shim-based global install flow (npm:/jsr:/https packages), `resolve_shim_data` computes the installation dir (`$DENO_INSTALL_ROOT/bin`, default `~/.deno/bin`, honoring `--root`), then the code verifies existing metadata is a directory and creates the tree with `create_dir_all` when absent. An existing non-directory at that path aborts the install.
Solutions
- Inspect the resolved dir: `ls -la "$DENO_INSTALL_ROOT" 2>/dev/null || ls -la ~/.deno`
- Fix or unset `DENO_INSTALL_ROOT` so it names a directory (deno creates `<root>/bin` if missing)
- Remove the file occupying the path and re-run the install
- Pass an explicit `--root <dir>`
Example fix
# before $ ls "$DENO_INSTALL_ROOT" ls: ... Not a directory $ deno install -g jsr:@luca/flag # Installation path is not a directory # after $ unset DENO_INSTALL_ROOT $ deno install -g jsr:@luca/flag # installs into ~/.deno/bin
Defensive patterns
Strategy: validation
Validate before calling
# Same pre-check as other install flows
BIN_DIR="${DENO_INSTALL_ROOT:-$HOME/.deno}"
BIN_DIR="${BIN_DIR%/bin}/bin"
mkdir -p "$BIN_DIR" && deno install -g "$PKG" Prevention
- Keep DENO_INSTALL_ROOT pointed at ~/.deno (or another directory) in all environments
- Include a `deno install -g jsr:@scope/pkg` smoke test in image builds to catch bad paths early
- Avoid `--root` values that are files or that contain a file named bin
When it happens
Trigger: `deno install -g <pkg>` when the resolved installation dir path is occupied by a regular file or symlink-to-file: misconfigured `DENO_INSTALL_ROOT`, a stray file named `bin` in the root, or `--root` given a file path.
Common situations: Shell profile exporting `DENO_INSTALL_ROOT` to a file; Docker images provisioning the wrong path; wrapper scripts passing `--root /some/file`.
Related errors
- Unexpected second argument to Deno.bench()
- Failed to install " " specifier. If you are trying to…
- The benchmark which this context belongs to is not being…
- Unexpected 'fn' field in options, bench function is already…
- Unexpected third argument to Deno.bench()
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/3ffceb29a5b7ee55.
Report an issue: GitHub.
Appendix: source
Thrown at cli/js/40_bench.js:171
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",
);
}
name = nameOrFnOrOptions.name ?? fn.name;
} else {
if (
!nameOrFnOrOptions.fn || typeof nameOrFnOrOptions.fn !== "function"
) {
throw new TypeError(
"Expected 'fn' field in the first argument to be a bench function",
);
}
fn = nameOrFnOrOptions.fn;
name = nameOrFnOrOptions.name ?? fn.name;
}
if (!name) {
throw new TypeError("The bench name can't be empty");
}
benchDesc = { ...defaults, ...nameOrFnOrOptions, fn, name };
}
const AsyncFunction = (async () => {}).constructor;
benchDesc.async = AsyncFunction === benchDesc.fn.constructor;
benchDesc.fn = wrapBenchmark(benchDesc);
benchDesc.warmup = false;
benchDesc.name = escapeName(benchDesc.name);
if (cachedOrigin == undefined) {View on GitHub (pinned to 9ad36f7a2c)