denoland/deno · error · AnyError

'{}' is owned by uid {}, not current uid {}

Error message

'{}' is owned by uid {}, not current uid {}

What it means

`ensure_secure_temp_dir` guards the `deno_nm` temp root/day-folder itself: it opens the directory with O_NOFOLLOW|O_DIRECTORY and requires the owner to be exactly the current effective uid. Unlike the ancestor walk, root ownership (uid 0) is NOT accepted here, because Deno must fully trust and manage this folder's contents.

Source

Thrown at cli/util/temp.rs:189

fn ensure_secure_temp_dir(path: &Path) -> Result<(), AnyError> {
  use std::os::unix::fs::MetadataExt;
  use std::os::unix::fs::OpenOptionsExt;
  use std::os::unix::fs::PermissionsExt;

  // Keep the check, permission repair, and final validation tied to the same
  // directory so replacing the path cannot redirect the chmod. The canonical
  // temp path and its ancestors are validated separately before subsequent
  // path-based use.
  let dir = std::fs::OpenOptions::new()
    .read(true)
    .custom_flags(libc::O_NOFOLLOW | libc::O_DIRECTORY)
    .open(path)?;

  // SAFETY: geteuid has no preconditions.
  let current_uid = unsafe { libc::geteuid() };
  let metadata = dir.metadata()?;
  if metadata.uid() != current_uid {
    bail!(
      "'{}' is owned by uid {}, not current uid {}",
      path.display(),
      metadata.uid(),
      current_uid
    );
  }

  let mode = metadata.permissions().mode();
  if mode & 0o077 != 0 {
    dir.set_permissions(std::fs::Permissions::from_mode(0o700))?;
  }

  let metadata = dir.metadata()?;
  if metadata.uid() != current_uid {
    bail!(
      "'{}' is owned by uid {}, not current uid {}",
      path.display(),
      metadata.uid(),

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Remove the foreign-owned folder: `sudo rm -rf /tmp/deno_nm` (it is a temp cache of node_modules; safe to delete).
  2. Or chown it to the current user: `sudo chown -R $(id -u) /tmp/deno_nm`.
  3. Give each user/container its own TMPDIR so they never collide on the same deno_nm path.
  4. Re-run as the user who owns the existing folder if that is the intended account.

Example fix

# before: /tmp/deno_nm was created by uid 1000, you are uid 1001
ls -ld /tmp/deno_nm     # drwx------ 1000 ...
deno install            # error: '/tmp/deno_nm' is owned by uid 1000, not current uid 1001

# after
sudo rm -rf /tmp/deno_nm
deno install
Defensive patterns

Strategy: validation

Validate before calling

# detect a foreign-owned deno_nm before running deno
d="${TMPDIR:-/tmp}/deno_nm"
if [ -e "$d" ] && [ "$(stat -c %u "$d")" != "$(id -u)" ]; then
  echo "deno_nm owned by uid $(stat -c %u "$d") — remove it or use a private TMPDIR"
fi

Prevention

When it happens

Trigger: Another account already created `<tmp>/deno_nm` (or the dated day folder under it) — a different user ran Deno first on a shared machine, you ran `sudo deno` after a user-level run (or vice versa), or a stale folder from an old uid remains after a uid change.

Common situations: Shared CI hosts where builds run as different service accounts with the same TMPDIR; sudo/user transitions; containers reusing a mounted /tmp volume across containers with different uids.

Related errors


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