oven-sh/bun · error · bun_install::Error

AccessDenied

Error message

AccessDenied

What it means

Installer error for permission-denied filesystem outcomes (the EACCES family): bun could not read or write a path under node_modules, the global install directory, or the cache because the OS refused it.

Source

Thrown at src/install/error.rs:5

#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
pub enum Error {
    #[error("FileNotFound")]
    FileNotFound,
    #[error("AccessDenied")]
    AccessDenied,
    #[error("NotDir")]
    NotDir,
    #[error("NameTooLong")]
    NameTooLong,
    #[error("SymLinkLoop")]
    SymLinkLoop,
    #[error("SystemFdQuotaExceeded")]
    SystemFdQuotaExceeded,
    #[error("SystemResources")]
    SystemResources,
    #[error("DeviceBusy")]
    DeviceBusy,
    #[error("TarballHTTP400")]
    TarballHTTP400,
    #[error("TarballHTTP401")]
    TarballHTTP401,
    #[error("TarballHTTP402")]

View on GitHub (pinned to 8c5296ac45)

Solutions

  1. Check ownership of the failing path: ls -la node_modules and the cache dir
  2. Reclaim it: sudo chown -R $(id -u):$(id -g) node_modules (or delete and reinstall)
  3. Do not mix sudo-installed package managers with bun on the same node_modules
  4. Point BUN_INSTALL and the cache to a user-writable location

Example fix

# before
sudo npm install   # creates root-owned node_modules
bun install        # -> AccessDenied

# after
sudo rm -rf node_modules
bun install
Defensive patterns

Strategy: validation

Validate before calling

import { accessSync, constants } from "node:fs";

try {
  accessSync("node_modules", constants.W_OK);
} catch {
  console.error("node_modules is not writable by this user; fix ownership first");
  process.exit(1);
}

Prevention

When it happens

Trigger: node_modules or the global bin dir owned by another user (mixing sudo npm with bun install); a read-only bind mount or Docker volume; a cache dir placed under a protected path; restrictive directory permissions.

Common situations: Previously ran npm/sudo as root so node_modules is root-owned; CI container runs as non-root but files were created by root; BUN_INSTALL pointing into /usr/local; shared machines with multiple users.

Related errors


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/7544d145a088abc8. Report an issue: GitHub.