denoland/deno · error

Path has no root.

Error message

Path has no root.

What it means

On Windows, Deno.statfs() canonicalizes the path, walks ancestors() to the last element (the drive root) and queries GetDiskFreeSpaceW. 'Path has no root.' (io::ErrorKind::NotFound) is the defensive fallback when that last ancestor is absent (ext/fs/std_fs.rs:1074). A canonicalized absolute Windows path always has a root, so this error is effectively unreachable through the public API and indicates an internal invariant break.

Source

Thrown at ext/fs/std_fs.rs:1074

        blocks: result.f_blocks as _,
        bfree: result.f_bfree as _,
        bavail: result.f_bavail as _,
        files: result.f_files as _,
        ffree: result.f_ffree as _,
      })
    }
  }
  #[cfg(windows)]
  {
    use std::ffi::OsStr;
    use std::os::windows::ffi::OsStrExt;

    use windows_sys::Win32::Storage::FileSystem::GetDiskFreeSpaceW;

    let _ = bigint;
    let path = path.canonicalize()?;
    let root = path.ancestors().last().ok_or_else(|| {
      std::io::Error::new(ErrorKind::NotFound, "Path has no root.")
    })?;
    let mut root = OsStr::new(root).encode_wide().collect::<Vec<_>>();
    root.push(0);
    let mut sectors_per_cluster = 0;
    let mut bytes_per_sector = 0;
    let mut available_clusters = 0;
    let mut total_clusters = 0;
    let mut code = 0;
    let mut retries = 0;
    // We retry here because libuv does: https://github.com/libuv/libuv/blob/fa6745b4f26470dae5ee4fcbb1ee082f780277e0/src/win/fs.c#L2705
    while code == 0 && retries < 2 {
      // SAFETY: Normal GetDiskFreeSpaceW usage.
      code = unsafe {
        GetDiskFreeSpaceW(
          root.as_ptr(),
          &mut sectors_per_cluster,
          &mut bytes_per_sector,
          &mut available_clusters,

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Pass an absolute path of an existing directory to Deno.statfs
  2. Update Deno — device-path handling in canonicalize has changed between versions
  3. If it still reproduces, file a Deno issue including the exact path string
Defensive patterns

Strategy: validation

Validate before calling

function statfsSafe(path: string): Deno.StatFs {
  const real = Deno.realPathSync(path); // absolute, existing path
  if (!real.startsWith('/') && !/^[A-Za-z]:[\\/]/.test(real)) {
    throw new Error(`Refusing statfs on non-absolute path: ${path}`);
  }
  return Deno.statfsSync(real);
}

Try / catch

try {
  const fs = Deno.statfsSync(dir);
} catch (e) {
  if (e instanceof Error && /Path has no root/.test(e.message)) {
    // defensive Deno check misfired — report with the exact path
    throw new Error(`Deno statfs failed to derive a drive root for: ${dir}`);
  }
  throw e;
}

Prevention

When it happens

Trigger: Not reproducible from JavaScript in practice; it would require canonicalize() to return a relative path on Windows (e.g. unusual device paths mis-resolving through a subst mapping or VERBATIM prefix).

Common situations: Essentially never seen; if it appears, it is a Deno bug tied to exotic path forms — worth reporting with the exact input path.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/c846e5fe48c7f7ec. Report an issue: GitHub.