denoland/deno · error · std::io::Error
failed to reading from {}: {}
Error message
failed to reading from {}: {} What it means
Deno passes its npm resolution state to child processes via the internal env var DENO_DONT_USE_INTERNAL_NODE_COMPAT_STATE_FD, whose value is either an fd number or a file path. After opening and seeking to the start, the state is read with read_to_end; any read failure is rewrapped with this message (naming 'fd N' or the path plus the OS error). It means the stream itself was unreadable — a closed or bad fd, or a path with permission/IO problems.
Source
Thrown at libs/npm_installer/process_state.rs:139
)
}
FdOrPath::Path(path) => Ok(
sys
.fs_open(path, &sys_traits::OpenOptions::new_read())?
.into_boxed(),
),
}
}
}
let fd_or_path = FdOrPath::parse(&value);
let mut file = fd_or_path.open(sys)?;
let mut buf = Vec::new();
// seek to beginning. after the file is written the position will be inherited by this subprocess,
// and also this file might have been read before
file.seek(std::io::SeekFrom::Start(0))?;
file.read_to_end(&mut buf).map_err(|err| {
std::io::Error::new(
err.kind(),
format!(
"failed to reading from {}: {}",
match fd_or_path {
FdOrPath::Fd(fd) => format!("fd {}", fd),
FdOrPath::Path(path) => path.display().to_string(),
},
err,
),
)
})?;
let state: NpmProcessState =
serde_json::from_slice(&buf).map_err(|err| {
std::io::Error::new(
ErrorKind::InvalidData,
format!(
"failed to deserialize npm process state: {}\n{}",
err,View on GitHub (pinned to 9ad36f7a2c)
Solutions
- Unset DENO_DONT_USE_INTERNAL_NODE_COMPAT_STATE_FD in your shell/CI environment — it is set automatically by a parent deno and must not be set by hand.
- If you spawn deno children yourself, pass the fd/path you just wrote, keep the fd open in the parent until the child has started, and make sure it is inherited.
- Ensure the parent and child are the same deno binary/version so the state handoff matches.
Example fix
# before export DENO_DONT_USE_INTERNAL_NODE_COMPAT_STATE_FD=3 # stale fd from an earlier run deno run main.ts # failed to reading from fd 3: ... # after unset DENO_DONT_USE_INTERNAL_NODE_COMPAT_STATE_FD deno run main.ts
Defensive patterns
Strategy: validation
Validate before calling
// if you spawn deno children yourself, validate the handoff before exec
fn state_source_valid(value: &std::ffi::OsStr) -> bool {
let s = value.to_string_lossy();
if let Ok(fd) = s.parse::<usize>() {
// fd must be open and readable right now
std::fs::File::from(std::os::unix::io::BorrowedFd::borrow_raw(fd as _)).metadata().is_ok()
} else {
std::path::Path::new(s).is_file()
}
} Try / catch
match NpmProcessState::from_env_var(sys, env_value) {
Ok(state) => { /* use state */ }
Err(err) if err.to_string().contains("failed to reading from") => {
// stale fd or unreadable path in DENO_DONT_USE_INTERNAL_NODE_COMPAT_STATE_FD;
// scrub the variable and re-resolve from scratch instead of trusting it
sys.env_remove_var("DENO_DONT_USE_INTERNAL_NODE_COMPAT_STATE_FD");
}
Err(err) => return Err(err),
} Prevention
- Never set or export DENO_DONT_USE_INTERNAL_NODE_COMPAT_STATE_FD yourself; it is an internal handoff variable managed by the parent deno process.
- When spawning deno from deno, keep the state fd open in the parent until the child has started, and confirm the fd is inherited.
- Keep one deno version across the whole process tree so fd/state handoffs stay compatible.
When it happens
Trigger: The child deno process reads the state stream and gets an IO error: the parent closed the fd before the child read it, the value in the env var names an fd that was never inherited, or the path is unreadable (deleted, permissions, different container mount).
Common situations: Manually setting DENO_DONT_USE_INTERNAL_NODE_COMPAT_STATE_FD (or leaking it from a previous deno run) in a shell/CI; process supervisors and wrappers that scrub or renumber file descriptors; version mismatch where an older deno parent spawns a newer deno child; containers where the path is not mounted in the child.
Related errors
- failed to deserialize npm process state: {}\n{}
- Invalid port: ''
- ERR_INVALID_FD
- refusing to materialize package into symlinked directory
- tar entry '{}' has invalid offset/size (offset={}, size={})
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/1985ee1be6e1ae6c.
Report an issue: GitHub.