{"record":{"id":"e6af48f9fd391e9c","repo":"swc-project/swc","slug":"module-string-names-unimplemented-e6af48","errorCode":null,"errorMessage":"module string names unimplemented","messagePattern":"module string names unimplemented","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_bundler/src/modules/sort/stmt.rs","lineNumber":574,"sourceCode":"}\n\nimpl Visit for RequirementCalculator {\n    noop_visit_type!();\n\n    weak!(visit_arrow_expr, ArrowExpr);\n\n    weak!(visit_function, Function);\n\n    weak!(visit_class_method, ClassMethod);\n\n    weak!(visit_private_method, PrivateMethod);\n\n    weak!(visit_method_prop, MethodProp);\n\n    fn visit_export_named_specifier(&mut self, n: &ExportNamedSpecifier) {\n        let orig = match &n.orig {\n            ModuleExportName::Ident(ident) => ident,\n            ModuleExportName::Str(..) => unimplemented!(\"module string names unimplemented\"),\n            #[cfg(swc_ast_unknown)]\n            _ => panic!(\"unable to access unknown nodes\"),\n        };\n        self.insert(orig.clone().into());\n    }\n\n    fn visit_assign_expr(&mut self, e: &AssignExpr) {\n        let old = self.in_assign_lhs;\n\n        self.in_assign_lhs = true;\n        e.left.visit_with(self);\n\n        self.in_assign_lhs = false;\n        e.right.visit_with(self);\n\n        self.in_assign_lhs = old;\n    }\n","sourceCodeStart":556,"sourceCodeEnd":592,"githubUrl":"https://github.com/swc-project/swc/blob/d7d74346665e36e692aa07e13d4ee3ee692ee35c/crates/swc_bundler/src/modules/sort/stmt.rs#L556-L592","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nexport { \"a\" as b };\n\n// after\nexport { a as b };","handlingStrategy":"validation","validationCode":"// Module-sort pass scans all statements: screen before bundle()\nuse swc_ecma_visit::{Visit, VisitWith};\nstruct SortSafe { ok: bool }\nimpl Visit for SortSafe {\n    fn visit_module_export_name(&mut self, n: &swc_ecma_ast::ModuleExportName) {\n        if matches!(n, swc_ecma_ast::ModuleExportName::Str(_)) { self.ok = false; }\n        n.visit_children_with(self);\n    }\n}\nlet mut v = SortSafe { ok: true };\nm.visit_with(&mut v);\nanyhow::ensure!(v.ok, \"module sorter will panic on string export names\");","typeGuard":"fn sort_safe(m: &swc_ecma_ast::Module) -> bool {\n    use swc_ecma_visit::{Visit, VisitWith};\n    struct F(bool); impl Visit for F {\n        fn visit_module_export_name(&mut self, n: &swc_ecma_ast::ModuleExportName) {\n            if matches!(n, swc_ecma_ast::ModuleExportName::Str(_)) { self.0 = false; }\n            n.visit_children_with(self);\n        }\n    }\n    let mut f = F(true); m.visit_with(&mut f); f.0\n}","tryCatchPattern":"let r = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| bundler.bundle(part)?));\nmatch r {\n    Ok(v) => v,\n    Err(p) if format!(\"{:?}\", &p).contains(\"module string names\") =>\n        Err(anyhow::anyhow!(\"string export name broke module sorting; normalize to identifiers\")),\n    Err(p) => std::panic::resume_unwind(p),\n}","preventionTips":["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."],"tags":["swc","bundler","esm","es2022","module-string-names","panic","module-sort"],"backgroundTag":null,"analyzedSha":"d7d74346665e36e692aa07e13d4ee3ee692ee35c","analyzedAt":"2026-08-16T12:41:13.160Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}