swc-project/swc · error
module string names unimplemented
Error message
module string names unimplemented
What it means
swc_bundler's module sorter scans statements to collect referenced Ids for dependency ordering (modules/sort/stmt.rs:574). Its visit_export_named_specifier only accepts identifier origs; `export { "a" as b }` (ModuleExportName::Str) hits unimplemented!() because there is no Id to insert into the ordering set. Bundling aborts with a panic (exit 101).
Source
Thrown at crates/swc_bundler/src/modules/sort/stmt.rs:574
}
impl Visit for RequirementCalculator {
noop_visit_type!();
weak!(visit_arrow_expr, ArrowExpr);
weak!(visit_function, Function);
weak!(visit_class_method, ClassMethod);
weak!(visit_private_method, PrivateMethod);
weak!(visit_method_prop, MethodProp);
fn visit_export_named_specifier(&mut self, n: &ExportNamedSpecifier) {
let orig = match &n.orig {
ModuleExportName::Ident(ident) => ident,
ModuleExportName::Str(..) => unimplemented!("module string names unimplemented"),
#[cfg(swc_ast_unknown)]
_ => panic!("unable to access unknown nodes"),
};
self.insert(orig.clone().into());
}
fn visit_assign_expr(&mut self, e: &AssignExpr) {
let old = self.in_assign_lhs;
self.in_assign_lhs = true;
e.left.visit_with(self);
self.in_assign_lhs = false;
e.right.visit_with(self);
self.in_assign_lhs = old;
}
View on GitHub (pinned to d7d7434666)
Solutions
- Normalize the export to identifier form in source.
- Shim or patch dependencies that use string origs.
- Add a pre-bundle SWC visitor converting ModuleExportName::Str to Ident.
- Externalize the module until upstream support lands.
Example fix
// before
export { "a" as b };
// after
export { a as b }; Defensive patterns
Strategy: validation
Validate before calling
// Module-sort pass scans all statements: screen before bundle()
use swc_ecma_visit::{Visit, VisitWith};
struct SortSafe { ok: bool }
impl Visit for SortSafe {
fn visit_module_export_name(&mut self, n: &swc_ecma_ast::ModuleExportName) {
if matches!(n, swc_ecma_ast::ModuleExportName::Str(_)) { self.ok = false; }
n.visit_children_with(self);
}
}
let mut v = SortSafe { ok: true };
m.visit_with(&mut v);
anyhow::ensure!(v.ok, "module sorter will panic on string export names"); Type guard
fn sort_safe(m: &swc_ecma_ast::Module) -> bool {
use swc_ecma_visit::{Visit, VisitWith};
struct F(bool); impl Visit for F {
fn visit_module_export_name(&mut self, n: &swc_ecma_ast::ModuleExportName) {
if matches!(n, swc_ecma_ast::ModuleExportName::Str(_)) { self.0 = false; }
n.visit_children_with(self);
}
}
let mut f = F(true); m.visit_with(&mut f); f.0
} Try / catch
let r = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| bundler.bundle(part)?));
match r {
Ok(v) => v,
Err(p) if format!("{:?}", &p).contains("module string names") =>
Err(anyhow::anyhow!("string export name broke module sorting; normalize to identifiers")),
Err(p) => std::panic::resume_unwind(p),
} Prevention
- A single reusable Str-name visitor guards against every swc_bundler panic in this family — install it once in your pipeline.
- Enforce identifier-only export names in repo style guides.
- Bundle-test new barrels and index files specifically.
- Watch swc release notes; when support lands, remove the screen.
When it happens
Trigger: Any module in the graph declares a named export whose orig is a string literal; during statement scanning for topological sort, the Str arm panics.
Common situations: Same family as the other module-string-name panics: ES2022 arbitrary module namespace names in sources or dependencies; shows up during bundler's ordering pass; tools built on swc_bundler (spack-style pipelines) fail with this message.
Related errors
- module string names unimplemented
- module string names unimplemented
- module string names unimplemented
- module string names unimplemented
- module string names unimplemented
AI-assisted analysis of swc-project/swc@d7d7434666 (2026-08-16).
Data as JSON: /api/errors/e6af48f9fd391e9c.
Report an issue: GitHub.