denoland/deno · error · TypeError
Unexpected third argument to Deno.bench()
Error message
Unexpected third argument to Deno.bench()
What it means
`install_global_compiled` takes the first element of `InstallFlagsGlobal::module_urls` and errors when the vec is empty. The public CLI grammar requires a module URL, so in practice this is an internal invariant that fires only when install flags are constructed programmatically (embedders, custom CLIs driving deno's install API) with an empty URL list.
Solutions
- Pass the entrypoint module URL (file path, https URL, or npm:/jsr: specifier) in module_urls
- Validate the user-supplied URL is non-empty before constructing the install command
- If hitting this via the CLI itself, check for a malformed/empty argument (e.g. an unset shell variable expanding to nothing)
Example fix
# before (empty variable expands to no URL)
deno install -g "$TOOL_URL"
# No module URL provided
# after
: "${TOOL_URL:?TOOL_URL must be set}"
deno install -g "$TOOL_URL" Defensive patterns
Strategy: validation
Validate before calling
# Require a non-empty URL before invoking install
: "${TOOL_URL:?module URL is required}"
deno install -g "$TOOL_URL" Prevention
- Fail fast on empty user input with parameter expansions like ${VAR:?}
- When embedding deno_lib, assert `!module_urls.is_empty()` before calling install
- Log the fully-assembled install command in wrappers to catch dropped arguments
When it happens
Trigger: Programmatically invoking the global install entry point with `InstallFlagsGlobal { module_urls: vec![], .. }` — e.g. a wrapper tool that builds the install command from user input and drops/empties the URL argument before calling deno.
Common situations: Custom package-manager wrappers around deno; scripts that template `deno install -g` invocations and fail to substitute the URL; refactors of deno_lib call sites.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Expected 'fn' field in the first argument to be a 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 second argument to Deno.bench()
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/23a4c5ffefe38c79.
Report an issue: GitHub.
Appendix: source
Thrown at cli/js/40_bench.js:149
"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",
);
}
name = nameOrFnOrOptions.name ?? fn.name;
} else {View on GitHub (pinned to 9ad36f7a2c)