{"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":null,"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/89f33cbef296a2b287f323d42de54c871fa69c77/libs/eszip/v2.rs#L1478-L1514","documentation":"When the graph contains an npm module, eszip looks its package requirement up in the provided validated npm resolution snapshot's root_packages map. If the req from the graph is not a root package of that snapshot, creation fails: the graph and the snapshot came from different resolutions.","triggerScenarios":"Building an eszip/compile output where the ModuleGraph was resolved against one npm state but the SerializedNpmResolutionSnapshot came from another — stale lockfile, node_modules changed between graph build and snapshot capture, mixed Deno versions in one pipeline.","commonSituations":"`deno compile` after editing npm dependencies without updating the lockfile; CI caching the lockfile but not node_modules (or vice versa); custom tooling assembling graph and snapshot from separate runs.","solutions":["Regenerate the lockfile/resolution so graph and snapshot come from one pass: `deno cache --lock-write` then rebuild the compile output","Clear cached state (lockfile, node_modules, DENO_DIR npm cache) and rebuild","If driving eszip programmatically, capture the snapshot from the same resolve pass that built the graph"],"exampleFix":"# before — graph resolved against new deps, snapshot from old lockfile\ndeno compile entry.ts   # Could not resolve package req ... missing in the provided npm snapshot\n\n# after — regenerate the lockfile so both share one resolution, then compile\ndeno cache --lock-write entry.ts && deno compile entry.ts","handlingStrategy":"validation","validationCode":"// every npm req in the graph must be a root package of the snapshot\nfor module in graph.modules() {\n  if let deno_graph::Module::Npm(npm) = module {\n    let req = npm.pkg_req_ref.req();\n    if !snapshot.root_packages.contains_key(req) {\n      anyhow::bail!(\"req {req} missing from npm snapshot — regenerate the lockfile\");\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Regenerate the lockfile whenever npm dependencies change: `deno cache --lock-write`","Capture the npm snapshot from the same resolve pass that built the graph","Do not mix graph, snapshot and lockfile artifacts from different Deno versions in one pipeline"],"tags":["eszip","npm","snapshot","lockfile","compile"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}