denoland/deno · error · TypeError
Expected 'fn' field in the first argument to be a bench func
Error message
Expected 'fn' field in the first argument to be a bench function
What it means
`deno desktop --hmr` spawns the project's dev server (e.g. Vite) and scans its stdout for a `Local: http://…` line. This error means the server process exited before printing any such line, so no URL was ever obtained. The server's own crash output is echoed above via log::info.
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 89f33cbef2)
Solutions
- Run the dev server command manually (e.g. `npm run dev`) and fix its startup error — the crash reason is the server's own output
- Install dependencies first (`npm install` or `deno install`) before `deno desktop --hmr`
- Free the occupied port or configure the server to use another one
- Check the toolchain version (Node/npm) matches the project's requirements
Example fix
# before deno desktop --hmr # dev server exits silently # after npm run dev # reproduce and fix the server's error (install deps, free port) deno desktop --hmr
Defensive patterns
Strategy: validation
Validate before calling
const portFree = await probeTcp('127.0.0.1', 5173) === 'closed';
if (!portFree) throw new Error('dev port busy — stop the other server first');
await run('npm', ['install']); // deps present so the server reaches its Local: line Try / catch
try {
await denoDesktopHmr();
} catch (e) {
if (/exited without printing a URL/.test(String(e))) {
const log = await runRaw('npm', ['run', 'dev']); // server's own crash output names the cause
throw new Error(`dev server crashed: ${log}`);
}
throw e;
} Prevention
- Install project dependencies before starting HMR mode
- Free the dev-server port before launching
- Verify `npm run dev` (or equivalent) starts cleanly on its own first
When it happens
Trigger: The dev server dies at startup: missing node_modules, port already in use, syntax/config error in vite.config.ts, or an unsupported Node version — and exits during the URL scan loop.
Common situations: First run without installing dependencies; another process holding the dev port; a broken vite/webpack config; CI environments where the dev server needs setup the script did not do.
Related errors
- Unexpected second argument to Deno.bench()
- The bench name can't be empty
- Unexpected 'name' field in options, bench name is already pr
- The bench function must have a name
- Unexpected third argument to Deno.bench()
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/3ffceb29a5b7ee55.
Report an issue: GitHub.