{"record":{"id":"112da83bb7142d3d","repo":"swc-project/swc","slug":"plan-does-not-contain-bundle-kind-for","errorCode":null,"errorMessage":"Plan does not contain bundle kind for {:?}","messagePattern":"Plan does not contain bundle kind for (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_bundler/src/bundler/chunk/mod.rs","lineNumber":110,"sourceCode":"            .collect::<Vec<_>>();\n\n        let merged: Vec<_> = if entries.len() == 1 {\n            entries\n                .into_iter()\n                .map(|(id, mut entry)| {\n                    self.merge_into_entry(&ctx, id, &mut entry, &mut all);\n\n                    #[cfg(debug_assertions)]\n                    tracing::debug!(\"Merged `{}` and it's dep into an entry\", id);\n\n                    (id, entry)\n                })\n                .map(|(id, module)| {\n                    let kind = plan\n                        .entries\n                        .get(&id)\n                        .unwrap_or_else(|| {\n                            unreachable!(\"Plan does not contain bundle kind for {:?}\", id)\n                        })\n                        .clone();\n                    Bundle {\n                        kind,\n                        id,\n                        module: module.into(),\n                    }\n                })\n                .collect()\n        } else {\n            entries\n                .into_iter()\n                .map(|(id, mut entry)| {\n                    let mut a = all.clone();\n                    self.merge_into_entry(&ctx, id, &mut entry, &mut a);\n\n                    #[cfg(debug_assertions)]\n                    tracing::debug!(\"Merged `{}` and it's dep into an entry\", id);","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_bundler/src/bundler/chunk/mod.rs#L92-L128","documentation":"After merging modules into bundles, swc_bundler looks each bundle's entry id up in the ChunkPlan (plan.entries) to recover its BundleKind. The plan and the merged-entry list are derived from the same module graph, so a missing id means the two data structures disagree — an internal chunk-planning invariant violation (this copy of the code is the non-inlining branch of the two).","triggerScenarios":"Running bundle generation where module ids differ between chunk planning and merging: custom loaders returning fresh ids per call (e.g. allocating a new Atom each load), virtual modules whose id is not stable across phases, or graphs where entry deduplication behaves differently in the plan vs the merge step.","commonSituations":"Custom ModuleRecord-building plugins or virtual-module loaders; bundling many entries that share dependencies; partial upgrades that leave swc_bundler and its sibling crates on mismatched versions.","solutions":["Update the whole swc workspace to a single version so chunk planning and merging run the same code","If you implement Load/Resolve/ModuleRecord, guarantee one stable id per resolved module (return the same id for the same path every time)","Simplify the entry list until the panic disappears to identify the conflicting entry, then report the reduced graph to swc"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Before bundling, assert every entry id is present in the module graph you feed in\nfn entries_known(entries: &[ModuleId], graph: &FxHashSet<ModuleId>) -> Result<(), String> {\n    for e in entries {\n        if !graph.contains(e) {\n            return Err(format!(\"entry {:?} missing from module graph\", e));\n        }\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"let modules = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {\n    bundler.bundle(&entries)?\n}));\nif modules.is_err() {\n    // fall back: bundle each entry separately (single-entry bundles avoid the merge/planning path)\n    for e in &entries { let _ = bundler.bundle(std::iter::once(e).collect())?; }\n}","preventionTips":["Keep all swc crates version-aligned","Make custom loaders return the same id for the same resolved path on every call","Avoid passing the same module as both entry and dependency of another entry","Wrap bundling in catch_unwind or a subprocess so panics degrade to a build error, not a crash"],"tags":["swc","bundler","chunk","internal-invariant"],"backgroundTag":"bundler-entry-planning-mismatch","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}