{"record":{"id":"5d2dd978403e053a","repo":"swc-project/swc","slug":"modules-reexported-with-export-as-foo-from-f","errorCode":null,"errorMessage":"Modules reexported with `export * as foo from './foo'` should be marked as a wrapped esm","messagePattern":"Modules reexported with `export \\* as foo from '\\./foo'` should be marked as a wrapped esm","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_bundler/src/bundler/chunk/merge.rs","lineNumber":1233,"sourceCode":"                                                                    module_var.into(),\n                                                                ),\n                                                                exported: Some(ns.name.clone()),\n                                                                is_type_only: false,\n                                                            },\n                                                        );\n                                                        extra.push(\n                                                            NamedExport {\n                                                                span: ns.span,\n                                                                specifiers: vec![specifier],\n                                                                src: None,\n                                                                with: None,\n                                                                type_only: false,\n                                                            }\n                                                            .into(),\n                                                        );\n                                                    }\n                                                    None => {\n                                                        unreachable!(\n                                                            \"Modules reexported with `export * as \\\n                                                             foo from './foo'` should be marked \\\n                                                             as a wrapped esm\"\n                                                        )\n                                                    }\n                                                }\n\n                                                // Remove `export * as foo from ''`\n                                                continue;\n                                            }\n                                            ModuleExportName::Str(..) => {\n                                                unimplemented!(\"module string names unimplemented\")\n                                            }\n                                            #[cfg(swc_ast_unknown)]\n                                            _ => panic!(\"unable to access unknown nodes\"),\n                                        }\n                                    }\n                                }","sourceCodeStart":1215,"sourceCodeEnd":1251,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_bundler/src/bundler/chunk/merge.rs#L1215-L1251","documentation":"swc_bundler merges re-exports while building chunks. For `export * as foo from './foo'` it emits a named export whose value is the wrapped-ESM module object of './foo', looked up in metadata recorded during import analysis (the same map behind scope.mark_as_wrapping_required). If the target module was never marked as a wrapped ESM, the lookup returns None and this unreachable!() fires. It is an internal invariant of the bundler, not a user-facing error channel.","triggerScenarios":"Calling swc_bundler's Bundler::bundle on a graph where a module contains `export * as ns from './dep'` and './dep' has no wrapped-esm context recorded — typically when './dep' is itself listed as an entry, participates in a dependency cycle that skips the marking step, or when a custom Load/Resolve implementation returns modules whose ids/contexts differ between analysis and merge.","commonSituations":"Barrel/index files that aggregate with `export * as utils from './utils'`; tooling that pins swc_ecma_* crates at versions different from swc_bundler; bundling packages that re-export CJS dependencies as namespaces; deno-style bundling entrypoints.","solutions":["Rewrite the offending re-export: replace `export * as foo from './foo'` with `import * as foo from './foo'; export { foo };` or explicit named re-exports (`export { a, b } from './foo'`) and rebuild","If the re-exported module is also an entry, remove it from the entry list (or stop re-exporting it) so it can be marked as wrapped ESM","If you implement Load/ModuleRecord, return stable, identical module ids for the same resolved path so analysis and merge agree","Align all swc crates to one release (cargo update within the same swc version) and, if it still panics, minimize the module graph and report it to the swc repo"],"exampleFix":"// before\nexport * as utils from './utils';\n\n// after\nimport * as utils from './utils';\nexport { utils };","handlingStrategy":"validation","validationCode":"// Scan module sources before bundling for `export * as ns from ...`\nfn uses_export_star_as(src: &str) -> bool {\n    src.lines().any(|l| {\n        let t = l.trim();\n        t.starts_with(\"export\") && t.contains(\"*\") && t.contains(\" as \") && t.contains(\"from\")\n    })\n}\n\nfor (path, src) in &sources {\n    if uses_export_star_as(src) {\n        eprintln!(\"skipping/rewriting {} (export * as unsupported)\", path);\n    }\n}","typeGuard":null,"tryCatchPattern":"let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {\n    bundler.bundle(&entries)?\n}));\nmatch result {\n    Ok(v) => v,\n    Err(payload) => {\n        let msg = payload\n            .downcast_ref::<String>()\n            .cloned()\n            .or_else(|| payload.downcast_ref::<&str>().map(|s| s.to_string()))\n            .unwrap_or_default();\n        if msg.contains(\"wrapped esm\") {\n            // rewrite `export * as` occurrences in inputs and retry once\n        } else {\n            std::panic::resume_unwind(payload);\n        }\n    }\n}","preventionTips":["Prefer named re-exports or `import * as x; export { x }` over `export * as x from` in code that will be bundled","Keep swc_bundler and all swc_ecma_* crates on the same release","If implementing Load/Resolve, return stable module ids per resolved path","Run bundling in a worker process so internal panics never take down the host"],"tags":["swc","bundler","esm","re-export","export-star-as"],"backgroundTag":"esm-reexport-bundling","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"}