denoland/deno · error · TypeError
Unexpected 'fn' field in options, bench function is already…
Error message
Unexpected 'fn' field in options, bench function is already provided as the second argument
What it means
In the compiled-binary global install flow, deno computes the output path (`<bin_dir>/<name>` or `<name>.exe` on Windows) and refuses to overwrite an existing file unless `--force`/`-f` is passed. Before recompiling it removes the old file so `deno compile`'s own overwrite-safety check (which guards against clobbering files it did not produce) does not fail; the removal error context even hints about running processes.
Solutions
- Re-run with `deno install -gf <url>` to overwrite the existing binary
- Or uninstall first: `deno uninstall <name>` then install again
- Or install under a different name: `deno install -g --name <other-name> <url>`
- On Windows, if removal still fails, stop running instances of the tool (check Task Manager) first
Example fix
# before $ deno install -g https://example.com/cli.ts # Existing installation found. Aborting (Use -f to overwrite). # after $ deno install -gf https://example.com/cli.ts # overwrites
Defensive patterns
Strategy: validation
Validate before calling
# Update flow: make overwrite explicit instead of relying on absent state
NAME="${NAME:-cli}" # name used at first install
BIN="${DENO_INSTALL_ROOT:-$HOME/.deno}/bin/$NAME"
[ -f "$BIN" ] && deno uninstall "$NAME"
deno install -g --name "$NAME" "$URL" Prevention
- Standardize tool-update scripts on `deno install -gf <url>`
- Record the `--name` used at first install so updates target the same path deliberately
- Treat the abort as intentional: never script blind overwrites of unknown files
When it happens
Trigger: `deno install -g <url>` when the target executable already exists on disk and no `-f` was given: a previous install of the same tool (same explicit `--name`, or same default name derived from the URL) is present.
Common situations: Re-running install to update a globally installed tool and forgetting `--force`; installing two different modules that resolve to the same output name.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- Unexpected second argument to Deno.bench()
- Expected 'fn' field in the first argument to be a bench…
- Failed to install " " specifier. If you are trying to…
- Unexpected third argument to Deno.bench()
- An executable name was not provided. One could not be…
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/53d16d74784e79a0.
Report an issue: GitHub.
Appendix: source
Thrown at cli/js/40_bench.js:162
}
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",
);
}
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");
}View on GitHub (pinned to 9ad36f7a2c)