{"record":{"id":"ebb41c4fbff361e5","repo":"swc-project/swc","slug":"swc-does-not-support-module-expressions","errorCode":null,"errorMessage":"swc does not support module expressions","messagePattern":"swc does not support module expressions","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_estree_compat/src/swcify/expr.rs","lineNumber":1146,"sourceCode":"\n    fn swcify(self, _: &Context) -> Self::Output {\n        panic!(\"swc does not support record expressions\")\n    }\n}\n\nimpl Swcify for TupleExpression {\n    type Output = Never;\n\n    fn swcify(self, _: &Context) -> Self::Output {\n        panic!(\"swc does not support tuple expressions\")\n    }\n}\n\nimpl Swcify for ModuleExpression {\n    type Output = Never;\n\n    fn swcify(self, _: &Context) -> Self::Output {\n        panic!(\"swc does not support module expressions\")\n    }\n}\n\nimpl Swcify for TSAsExpression {\n    type Output = TsAsExpr;\n\n    fn swcify(self, ctx: &Context) -> Self::Output {\n        TsAsExpr {\n            span: ctx.span(&self.base),\n            expr: self.expression.swcify(ctx),\n            type_ann: self.type_annotation.swcify(ctx),\n        }\n    }\n}\n\nimpl Swcify for TSTypeAssertion {\n    type Output = TsTypeAssertion;\n","sourceCodeStart":1128,"sourceCodeEnd":1164,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_estree_compat/src/swcify/expr.rs#L1128-L1164","documentation":"Swcify in swc_estree_compat maps swc_estree_ast nodes onto swc_ecma_ast. ModuleExpression (the `module { ... }` inline-module proposal) has no SWC AST representation, so the impl declares `Output = Never` and panics. Conversion of an AST containing a module expression is impossible by design.","triggerScenarios":"Calling `.swcify(ctx)` on an ESTree tree that includes a ModuleExpression node, i.e. code using `module { ... }` parsed with the module-blocks syntax plugin (babel syntax-plugin-module-blocks or similar) before being converted to SWC.","commonSituations":"Experimenting with module expressions in a babel pipeline that later hands the AST to SWC; shared parser configs enabling stage-1 syntax; codemod tools that accept arbitrary ESTree and convert it.","solutions":["Turn off the module-blocks syntax plugin in the upstream ESTree parser","Transform `module { ... }` code into a function/IIFE returning an importable object before conversion","Parse with swc_ecma_parser directly, avoiding ESTree conversion of proposal syntax","Pre-scan the ESTree JSON for `type: \"ModuleExpression\"` and surface a user-facing error"],"exampleFix":"// before\nlet m = module { export default 1; }; // module-blocks syntax\nast.swcify(&ctx);                      // panics: swc does not support module expressions\n\n// after\nlet m = (() => ({ default: 1 }))();   // lowered to standard JS\nast.swcify(&ctx);                      // ok","handlingStrategy":"type-guard","validationCode":"let mut bad = Vec::new();\nfind_unsupported(&estree_json, &mut bad); // same walk as error 200\nif bad.iter().any(|t| t == \"ModuleExpression\") {\n    return Err(\"module expressions (module { ... }) are not supported by swcify\".into());\n}","typeGuard":"fn is_unsupported_estree_type(t: &str) -> bool {\n    matches!(\n        t,\n        \"ModuleExpression\" | \"RecordExpression\" | \"TupleExpression\"\n            | \"PipelinePrimaryTopicReference\" | \"BindExpression\" | \"DoExpression\"\n    )\n}","tryCatchPattern":"let out = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {\n    estree_expr.swcify(&ctx)\n}));\nif out.is_err() {\n    return Err(\"swcify cannot convert this ESTree tree (module expression present)\".into());\n}","preventionTips":["Leave module-blocks syntax plugins off for inputs destined for swcify","Lower `module { ... }` to standard JS before conversion","Validate ESTree JSON types against the unsupported-node blocklist","Use swc_ecma_parser directly for source parsing"],"tags":["estree-compat","swcify","ast-conversion","module-expressions","panic"],"backgroundTag":"unsupported-syntax-feature","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"}