{"record":{"id":"0501a98aa4ab4dbe","repo":"swc-project/swc","slug":"module-string-names-unimplemented-0501a9","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/bundler/finalize.rs","lineNumber":227,"sourceCode":"                                    ExportSpecifier::Namespace(..) => {\n                                        // unreachable\n                                    }\n                                    ExportSpecifier::Default(s) => {\n                                        props.push(PropOrSpread::Prop(Box::new(Prop::KeyValue(\n                                            KeyValueProp {\n                                                key: PropName::Ident(IdentName::new(\n                                                    atom!(\"default\"),\n                                                    DUMMY_SP,\n                                                )),\n                                                value: s.exported.into(),\n                                            },\n                                        ))));\n                                    }\n                                    ExportSpecifier::Named(s) => match s.exported {\n                                        Some(ModuleExportName::Ident(exported)) => {\n                                            let orig = match s.orig {\n                                                ModuleExportName::Ident(ident) => ident,\n                                                ModuleExportName::Str(..) => unimplemented!(\n                                                    \"module string names unimplemented\"\n                                                ),\n                                                #[cfg(swc_ast_unknown)]\n                                                _ => panic!(\"unable to access unknown nodes\"),\n                                            };\n                                            props.push(PropOrSpread::Prop(Box::new(\n                                                Prop::KeyValue(KeyValueProp {\n                                                    key: PropName::Ident(exported.into()),\n                                                    value: orig.into(),\n                                                }),\n                                            )));\n                                        }\n                                        Some(ModuleExportName::Str(..)) => {\n                                            unimplemented!(\"module string names unimplemented\")\n                                        }\n                                        #[cfg(swc_ast_unknown)]\n                                        Some(_) => panic!(\"unable to access unknown nodes\"),\n                                        None => {","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/swc-project/swc/blob/d7d74346665e36e692aa07e13d4ee3ee692ee35c/crates/swc_bundler/src/bundler/finalize.rs#L209-L245","documentation":"During finalize, swc_bundler builds the runtime export object for a chunk and iterates named export specifiers. At finalize.rs:227 an export whose orig is a string (`export { \"orig\" as name }`, ModuleExportName::Str) reaches unimplemented!() because the generated KeyValueProp needs a real Ident binding, and a string name has none. The panic aborts bundling with exit code 101.","triggerScenarios":"The bundle graph contains `export { \"some name\" as alias }` (or the equivalent re-export from another module); finalize tries to emit `exports.alias = <binding>` and cannot resolve a binding for a string orig.","commonSituations":"Final-stage failures when bundling generated code (GraphQL codegen, i18n key modules) that uses string-named exports; a bundle that passes earlier passes and only dies at chunk finalization.","solutions":["Change the export to reference a real identifier binding and re-bundle.","If the string name is required by consumers, expose it via a namespace object (`const ns = { \"some name\": value }; export { ns }`) instead of a string export specifier.","Patch the offending dependency or pre-transform sources before bundling.","Track swc_bundler's module-string-names support and remove the workaround after upgrading."],"exampleFix":"// before\nexport { \"some name\" as someName };\n\n// after\nconst someName = /* the actual binding */ 1;\nexport { someName };","handlingStrategy":"validation","validationCode":"// Screen every module in the Loader before the bundler stores it\nimpl Load for MyLoader {\n    fn load(&self, f: &FileName) -> Result<ModuleRecord, Error> {\n        let rec = self.inner.load(f)?;\n        let mut bad = StrExportScan::default();\n        rec.module.visit_with(&mut bad);\n        if !bad.locations.is_empty() {\n            anyhow::bail!(\"{} uses string-named exports ({:?}); unsupported by swc_bundler\", f, bad.locations);\n        }\n        Ok(rec)\n    }\n}","typeGuard":"fn exports_are_identifier_only(m: &swc_ecma_ast::Module) -> bool {\n    use swc_ecma_visit::{Visit, VisitWith};\n    struct Ok_(bool); impl Visit for Ok_ {\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 v = Ok_(true); m.visit_with(&mut v); v.0\n}","tryCatchPattern":"// finalize runs after most work; prefer load-time screening. If you must catch:\nif let Err(p) = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| bundler.bundle(part)?)) {\n    if format!(\"{:?}\", &p).contains(\"module string names\") {\n        log::error!(\"chunk finalize hit a string-named export; offending module list: {:?}\", module_paths);\n        return Err(anyhow::anyhow!(\"unsupported ES2022 string export name\"));\n    }\n    std::panic::resume_unwind(p);\n}","preventionTips":["Screen modules inside your Load implementation — it is the single choke point every file passes through.","Keep string-keyed APIs behind exported objects, not export specifiers.","Alert on any dependency diff that introduces `export { \"`.","Add fixture tests bundling each dependency category (CJS, ESM, generated) to catch regressions early."],"tags":["swc","bundler","esm","es2022","module-string-names","panic","finalize","exports"],"backgroundTag":null,"analyzedSha":"d7d74346665e36e692aa07e13d4ee3ee692ee35c","analyzedAt":"2026-08-16T12:41:13.160Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}