oven-sh/bun · error
LazyPackageDestinationDir is closed! This should never…
Error message
LazyPackageDestinationDir is closed! This should never happen. Why did this happen?! It's not your fault. Its our fault. We're sorry.
What it means
Internal invariant violated: LazyPackageDestinationDir was used after being closed. The enum wrapper around a package destination directory was consumed (closed) and then accessed again — a Bun-internal lifecycle bug, not user error.
Solutions
- Report this as a GitHub issue at https://github.com/oven-sh/bun/issues
- Try clearing node_modules and reinstalling from scratch
- Upgrade to the latest Bun version as the internal lifecycle bug may be fixed
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at src/install/PackageInstaller.rs:394 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16).
Data as JSON: /api/errors/05b70ffa96b53723.
Report an issue: GitHub.
Appendix: source
Thrown at src/install/PackageInstaller.rs:394
}
impl<'a> LazyPackageDestinationDir<'a> {
#[allow(dead_code)]
pub(crate) fn get_dir(&mut self) -> crate::Result<Fd> {
match self {
LazyPackageDestinationDir::Dir(fd) => Ok(*fd),
LazyPackageDestinationDir::Owned(dir) => Ok(dir.fd()),
LazyPackageDestinationDir::NodeModulesPath {
node_modules,
root_node_modules_dir,
} => {
let dir = node_modules.open_dir(Dir::borrow(root_node_modules_dir))?;
let fd = dir.fd();
*self = LazyPackageDestinationDir::Owned(dir);
Ok(fd)
}
LazyPackageDestinationDir::Closed => {
panic!(
"LazyPackageDestinationDir is closed! This should never happen. Why did this happen?! It's not your fault. Its our fault. We're sorry."
)
}
}
}
fn close(&mut self) {
*self = LazyPackageDestinationDir::Closed;
}
}
/// A dependency alias becomes the install destination inside `node_modules`
/// (the existing entry is renamed aside, deleted, and re-created). Reject
/// anything that could escape `node_modules`: empty names, `.`/`..`
/// components, absolute paths, drive letters, backslashes, NUL bytes, and any
/// separator other than the single `/` in a scoped name (`@scope/name`).
pub(crate) fn alias_is_safe_install_target(alias: &[u8]) -> bool {
if alias.is_empty() || alias.len() >= MAX_PATH_BYTES || strings::contains_any(alias, b"\\:\0") {View on GitHub (pinned to 8c5296ac45)