denoland/deno · error
Did not format non-workspace directory. Run again specifying
Error message
Did not format non-workspace directory. Run again specifying the current directory (ex. `deno fmt .`)
What it means
Thrown by `deno fmt` when it is run with no path arguments in a directory that is not part of a Deno workspace (no deno.json/deno.jsonc at or above the cwd). Deno warns that the entire directory will be formatted and asks for confirmation; if the prompt is declined, or stdin is not an interactive TTY so the confirm call returns false, formatting is aborted with this bail.
Source
Thrown at cli/tools/fmt.rs:235
|| cli_options.workspace().package_jsons().next().is_some()
{
return Ok(());
}
let confirm_result =
util::console::confirm(util::console::ConfirmOptions {
default: true,
message: format!(
"{} It looks like you're not in a workspace. Are you sure you want to format the entire '{}' directory?",
colors::yellow("Warning"),
cli_options.initial_cwd().display()
),
})
.unwrap_or(false);
if confirm_result {
Ok(())
} else {
bail!(
"Did not format non-workspace directory. Run again specifying the current directory (ex. `deno fmt .`)"
)
}
}
async fn format_files(
caches: &Arc<Caches>,
cli_options: &Arc<CliOptions>,
fmt_flags: &FmtFlags,
paths_with_options_batches: Vec<PathsWithOptions>,
) -> Result<(), AnyError> {
let formatter: Box<dyn Formatter> = if fmt_flags.check {
let fail_fast = fmt_flags.fail_fast || cli_options.is_quiet();
Box::new(CheckFormatter::new(fail_fast))
} else {
Box::new(RealFormatter::default())
};
let editorconfig_cache = Arc::new(EditorConfigCache::new());View on GitHub (pinned to 9ad36f7a2c)
Solutions
- Run `deno fmt .` (or `deno fmt <path>`) — an explicit path skips the confirmation entirely
- Create a deno.json or deno.jsonc at the project root so the directory becomes a workspace
- cd into the actual project directory before running `deno fmt`
Example fix
# before
deno fmt # not in a workspace, prompt auto-declines in CI
# after
deno fmt . # explicit path, no prompt
# or make the directory a workspace:
echo '{ "fmt": {} }' > deno.json Defensive patterns
Strategy: validation
Validate before calling
# in scripts/CI, always pass an explicit path and require a workspace config:
test -f deno.json || test -f deno.jsonc || { echo 'no deno.json: create one first'; exit 1; }
deno fmt . # explicit path never triggers the confirmation Prevention
- Never invoke bare `deno fmt` in scripts or CI — always `deno fmt <path>`
- Keep a deno.json/deno.jsonc at every project root so fmt always has a workspace
- Remember non-TTY stdin auto-declines the prompt; don't rely on the default 'yes'
When it happens
Trigger: Running bare `deno fmt` outside any workspace and answering 'n' to the yellow warning prompt; running `deno fmt` in CI or in a script where stdin is a pipe (not a TTY), so util::console::confirm resolves to its unwrap_or(false) default; running fmt from a parent/home directory that has no deno config.
Common situations: Fresh projects without a deno.json yet; running fmt from the wrong shell cwd; CI pipelines where the confirmation prompt cannot be answered and silently auto-declines.
Related errors
- No target files found.
- Missing bench function
- Unexpected 'fn' field in options, bench function is already
- Bench attempted to exit with exit code: ${exitCode}
- Invalid type for fetch: must be a function
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/cb08d617047dafab.
Report an issue: GitHub.