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

FileNotFound

Error message

FileNotFound

What it means

Unit variant of bun_install::Error (the installer's thiserror enum) surfaced as "FileNotFound" when an install-time filesystem path that must exist does not — the ENOENT-equivalent outcome of the installer's file operations such as reading package.json, the lockfile, cached tarballs, or node_modules paths.

Source

Thrown at src/install/error.rs:3

#[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")]

View on GitHub (pinned to 8c5296ac45)

Solutions

  1. Run bun install from the directory containing package.json
  2. Remove the stale lockfile and rebuild: rm bun.lock && rm -rf node_modules && bun install
  3. Verify BUN_INSTALL_CACHE_DIR points at an existing directory
  4. Re-run once to rule out a concurrent process deleting files mid-install

Example fix

# before
cd packages/web && bun install   # no package.json here

# after
cd /repo && bun install           # root/workspace with package.json
Defensive patterns

Strategy: validation

Validate before calling

import { existsSync } from "node:fs";

if (!existsSync("package.json")) {
  console.error("no package.json in", process.cwd());
  process.exit(1);
}

Try / catch

const p = Bun.spawnSync(["bun", "install"]);
if (p.stderr.toString().includes("FileNotFound")) {
  // re-check cwd, lockfile, and cache dir before retrying
}

Prevention

When it happens

Trigger: `bun install` run in a directory without package.json; a lockfile/cache entry pointing at a tarball deleted from the cache; lifecycle scripts or external tools moving/deleting files mid-install.

Common situations: Wrong cwd in CI or Docker layers; BUN_INSTALL_CACHE_DIR retargeted or emptied; partial node_modules left by a crashed earlier install; scripts pruning files during install.

Related errors


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