{"record":{"id":"3ffceb29a5b7ee55","repo":"denoland/deno","slug":"expected-fn-field-in-the-first-argument-to-be-a","errorCode":null,"errorMessage":"Expected 'fn' field in the first argument to be a bench function","messagePattern":"Expected 'fn' field in the first argument to be a bench function","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"cli/js/40_bench.js","lineNumber":171,"sourceCode":"      fn: nameOrFnOrOptions,\n      name: nameOrFnOrOptions.name,\n    };\n  } else {\n    let fn;\n    let name;\n    if (typeof optionsOrFn === \"function\") {\n      fn = optionsOrFn;\n      if (nameOrFnOrOptions.fn != undefined) {\n        throw new TypeError(\n          \"Unexpected 'fn' field in options, bench function is already provided as the second argument\",\n        );\n      }\n      name = nameOrFnOrOptions.name ?? fn.name;\n    } else {\n      if (\n        !nameOrFnOrOptions.fn || typeof nameOrFnOrOptions.fn !== \"function\"\n      ) {\n        throw new TypeError(\n          \"Expected 'fn' field in the first argument to be a bench function\",\n        );\n      }\n      fn = nameOrFnOrOptions.fn;\n      name = nameOrFnOrOptions.name ?? fn.name;\n    }\n    if (!name) {\n      throw new TypeError(\"The bench name can't be empty\");\n    }\n    benchDesc = { ...defaults, ...nameOrFnOrOptions, fn, name };\n  }\n\n  const AsyncFunction = (async () => {}).constructor;\n  benchDesc.async = AsyncFunction === benchDesc.fn.constructor;\n  benchDesc.fn = wrapBenchmark(benchDesc);\n  benchDesc.warmup = false;\n  benchDesc.name = escapeName(benchDesc.name);\n  if (cachedOrigin == undefined) {","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/js/40_bench.js#L153-L189","documentation":"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.","triggerScenarios":"`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.","commonSituations":"Shell profile exporting `DENO_INSTALL_ROOT` to a file; Docker images provisioning the wrong path; wrapper scripts passing `--root /some/file`.","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>`"],"exampleFix":"# before\n$ ls \"$DENO_INSTALL_ROOT\"\nls: ... Not a directory\n$ deno install -g jsr:@luca/flag\n# Installation path is not a directory\n\n# after\n$ unset DENO_INSTALL_ROOT\n$ deno install -g jsr:@luca/flag  # installs into ~/.deno/bin","handlingStrategy":"validation","validationCode":"# Same pre-check as other install flows\nBIN_DIR=\"${DENO_INSTALL_ROOT:-$HOME/.deno}\"\nBIN_DIR=\"${BIN_DIR%/bin}/bin\"\nmkdir -p \"$BIN_DIR\" && deno install -g \"$PKG\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["install","global-install","install-root","shim"],"backgroundTag":"path-is-not-a-directory","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}