{"record":{"id":"4459b7d713e71ffd","repo":"denoland/deno","slug":"could-not-resolve-package-req-from-graph-beca","errorCode":null,"errorMessage":"Could not resolve package req '{}' from graph because it was missing in the provided npm snapshot.","messagePattern":"Could not resolve package req '(.+?)' from graph because it was missing in the provided npm snapshot\\.","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"libs/eszip/v2.rs","lineNumber":1496,"sourceCode":"        }\n        deno_graph::Module::Json(module) => {\n          let eszip_module = EszipV2Module::Module {\n            kind: ModuleKind::Json,\n            source: EszipV2SourceSlot::Ready(module.source.text.clone().into()),\n            source_map: EszipV2SourceSlot::Ready(Arc::new([])),\n          };\n          modules.insert(specifier_key.into_owned(), eszip_module);\n          Ok(None)\n        }\n        deno_graph::Module::Npm(module) => {\n          let Some(npm_packages) = npm_packages else {\n            return Ok(None);\n          };\n\n          let req_ref = &module.pkg_req_ref;\n          let serialize_npm_snapshot = npm_snapshot.as_serialized();\n          let pkg_id = serialize_npm_snapshot.root_packages.get(req_ref.req())\n            .ok_or_else(|| anyhow::anyhow!(\"Could not resolve package req '{}' from graph because it was missing in the provided npm snapshot.\", req_ref.req()))?;\n          let pkg_nv = &pkg_id.nv;\n          let pkg_nv_reference =\n            NpmPackageNvReference::new(PackageNvReference {\n              nv: pkg_nv.clone(),\n              sub_path: req_ref.sub_path().map(|s| s.into()),\n            });\n\n          if visited.should_visit_package_meta() {\n            let meta_modules = npm_packages.take_meta_modules(pkg_nv.clone());\n            let package_jsons = npm_packages.take_package_jsons(pkg_nv.clone());\n\n            for meta_module in\n              meta_modules.into_iter().chain(package_jsons).flatten()\n            {\n              modules.insert(\n                meta_module.specifier,\n                EszipV2Module::Module {\n                  kind: ModuleKind::OpaqueData,","sourceCodeStart":1478,"sourceCodeEnd":1514,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/libs/eszip/v2.rs#L1478-L1514","documentation":"When serializing npm modules into an eszip, Deno maps each npm package requirement found in the graph (module.pkg_req_ref) to a package id via the provided serialized npm resolution snapshot's root_packages table. If the requirement is absent from the snapshot, serialization aborts: the module graph references an npm package the snapshot never resolved. This indicates graph/snapshot skew, not a network problem.","triggerScenarios":"Building an eszip with a graph produced by one resolution pass and a snapshot (from deno.lock / ByonmNpmResolver) from another — e.g. lockfile updated between passes; embedding code reusing a cached graph after package.json changed; version mismatch between deno_graph semantics and the snapshot format.","commonSituations":"deno compile failing after editing package.json dependencies without regenerating deno.lock; CI caching DENO_DIR partially (graph cached, lock regenerated); custom tooling on the eszip crate feeding a stale SerializedNpmResolutionSnapshot.","solutions":["Delete deno.lock (and DENO_DIR cache if reused) and let the build re-resolve graph and snapshot together","Run `deno cache <entry>` successfully before compiling so graph and lockfile agree","Ensure only one process/version of Deno produces both the graph and the npm snapshot in your build pipeline","If it persists on a clean tree, report it — graph/snapshot skew on unmodified projects is a Deno bug"],"exampleFix":"# before\ndeno compile src/mod.ts  # Could not resolve package req 'foo@^2' ...\n\n# after\nrm deno.lock && deno cache src/mod.ts && deno compile src/mod.ts","handlingStrategy":"try-catch","validationCode":"# Keep graph and npm snapshot in lockstep: regenerate both together\nrm -f deno.lock && deno cache src/mod.ts  # exits non-zero if resolution fails","typeGuard":null,"tryCatchPattern":"// In pipelines invoking deno compile\nif (!cmd.success && stderr.includes(\"missing in the provided npm snapshot\")) {\n  // graph/snapshot skew: wipe lockfile + cache and rebuild once\n  await run(\"rm -f deno.lock\");\n  await run(\"deno cache src/mod.ts\");\n  await run(\"deno compile -o app src/mod.ts\");\n}","preventionTips":["Never mix a cached module graph with a freshly generated deno.lock","Pin one Deno version across your build pipeline","Treat any package.json/lockfile change as a signal to rebuild graphs from scratch"],"tags":["eszip","npm","resolution","lockfile","compile"],"backgroundTag":"npm-resolution-mismatch","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}