swc-project/swc · error

failed to merge into {}: module {} does not exist in the map

Error message

failed to merge into {}: module {} does not exist in the map

What it means

Raised in merge_into_entry (bundler merge.rs:125). While folding dependency modules into the entry module's namespace object, the code removes each dependency from the merged-modules map; the invariant is that every dependency id was inserted earlier. If all.remove(id) returns None, the map is missing an expected module (bookkeeping divergence between chunk selection and merging), and the panic fires naming the missing module id.

Source

Thrown at crates/swc_bundler/src/bundler/chunk/merge.rs:125

                {
                    let helpers = *entry_info.swc_helpers.lock();
                    let dep_helpers = *dep_info.swc_helpers.lock();

                    let helpers = Helpers::from_data(helpers);
                    let dep_helpers = Helpers::from_data(dep_helpers);

                    helpers.extend_from(&dep_helpers);

                    *entry_info.swc_helpers.lock() = helpers.data();
                }

                if *id == entry_id {
                    return Modules::empty(injected_ctxt);
                }

                all.remove(id).unwrap_or_else(|| {
                    unreachable!(
                        "failed to merge into {}: module {} does not exist in the map",
                        entry_id, id
                    )
                })
            });

            for dep in deps {
                entry.add_dep(dep);
            }

            self.replace_import_specifiers(&entry_info, entry);
            self.finalize_merging_of_entry(ctx, entry_id, entry);
            self.remove_wrong_exports(ctx, &entry_info, entry);
        })
    }

    #[allow(clippy::only_used_in_recursion)]
    fn collect_all_deps(

View on GitHub (pinned to 5176682b65)

Solutions

  1. Log the chunk's full dependency list and the map keys before merging to find where the module was dropped
  2. Ensure modules filtered out of merging (e.g. via keepModules or external config) are also excluded from the entry's dependency iteration
  3. Replace the panic with an Error::ModuleNotFound-style diagnostic carrying the module id
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_bundler/src/bundler/chunk/merge.rs:125 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/9f481fe85d9b8c8e. Report an issue: GitHub.