denoland/deno · error
Unhandled scenario where a duplicate entry was found: {:?}
Error message
Unhandled scenario where a duplicate entry was found: {:?} What it means
Panic while building a `deno compile` binary (cli/standalone/binary.rs). For compiled binaries Deno constructs a virtual filesystem from the local node_modules cache and flattens the per-registry directories (e.g. a localhost registry cache) into node_modules, keyed by entry name. Two entries resolving to the same package name collide, which the VFS builder does not know how to merge, so it panics with the duplicate entry.
Source
Thrown at cli/standalone/binary.rs:1533
npm_resolver.known_registries_dirnames().to_vec();
let mut localhost_entries: IndexMap<String, VfsEntry> = IndexMap::new();
let mut registry_top_segments: HashSet<String> = HashSet::new();
for registry_dirname in &known_registries_dirnames {
if let Some(first) = registry_dirname.split('/').next()
&& !first.is_empty()
{
registry_top_segments.insert(first.to_string());
}
let registry_path = global_cache_root_path.join(registry_dirname);
let Some(registry_dir) = vfs.get_dir_mut(®istry_path) else {
continue;
};
for entry in registry_dir.entries.take_inner() {
log::debug!("Flattening {} into node_modules", entry.name());
if let Some(existing) =
localhost_entries.insert(entry.name().to_string(), entry)
{
panic!(
"Unhandled scenario where a duplicate entry was found: {:?}",
existing
);
}
}
}
let Some(root_dir) = vfs.get_dir_mut(global_cache_root_path) else {
return vfs.build();
};
root_dir.name = DENO_COMPILE_GLOBAL_NODE_MODULES_DIR_NAME.to_string();
let mut new_entries = Vec::with_capacity(root_dir.entries.len());
for entry in root_dir.entries.take_inner() {
match &entry {
VfsEntry::Dir(dir) if registry_top_segments.contains(&dir.name) => {
// The packages under this registry host dir have already been
// flattened into `localhost_entries`. Drop the (now empty)View on GitHub (pinned to 9ad36f7a2c)
Solutions
- Clear the package cache and re-resolve from a single registry: `deno clean` (or remove DENO_DIR's npm cache) then `deno install` and retry `deno compile`
- Align registry configuration (.npmrc / NPM_CONFIG_REGISTRY / lockfile) so all packages resolve from one source before compiling
- If it persists with one consistent registry, report it to the deno repo with the import map, deno.json, and the duplicate entry name from the panic message
Example fix
# before # cache holds same package from registry + localhost mirror deno compile main.ts # panics: duplicate entry # after deno clean deno install deno compile main.ts
Defensive patterns
Strategy: fallback
Validate before calling
# before compiling, assert one registry produced the cache deno info --json 2>/dev/null | grep -i registry || true # simplest guard: start from a clean, single-registry cache deno clean && deno install --frozen && deno compile main.ts
Try / catch
# build script fallback: retry once after cleaning the cache
deno compile --output app main.ts || {
echo 'compile failed; retrying after deno clean' >&2
deno clean && deno install --frozen
deno compile --output app main.ts
} Prevention
- Keep one registry configuration (.npmrc, lockfile) per project and commit the lockfile
- Avoid mixing mirror/localhost registries with the public npm registry in the same cache lifecycle
- Run `deno clean` when switching registry providers before producing compile artifacts
When it happens
Trigger: Running `deno compile` on a project whose dependencies were resolved from multiple registry sources that both contributed a package with the same name into the global cache being flattened — e.g. an npm registry plus a localhost/mirrored registry ( Verdaccio proxy) yielding duplicate top-level entries.
Common situations: Compiling a project after switching registry configuration (custom .npmrc/registry mirrors, `nodeModulesDir` caches from different registries) so the same package exists twice under different registry roots in the DENO_DIR cache.
Related errors
- path not found (not dir): {}
- path not found (entry missing): {}
- BenchContext::end() has already been invoked
- Either `node` or `range` must be provided when reporting an
- Invalid range. Start value is bigger than end value: [${star
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/eb296676af141b9d.
Report an issue: GitHub.