{"record":{"id":"eb1ed4dc247e17d2","repo":"swc-project/swc","slug":"failed-to-parse-jsx-option-is-not-an-expr-eb1ed4","errorCode":null,"errorMessage":"failed to parse jsx option {}: '{}' is not an expression","messagePattern":"failed to parse jsx option (.+?): '(.+?)' is not an expression","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_react/src/jsx/mod.rs","lineNumber":173,"sourceCode":"        None,\n        &mut Vec::new(),\n    )\n    .map_err(|e| {\n        if HANDLER.is_set() {\n            HANDLER.with(|h| {\n                e.into_diagnostic(h)\n                    .note(\"Failed to parse jsx pragma\")\n                    .emit()\n            })\n        }\n    })\n    .map(drop_span)\n    .map(|mut expr| {\n        apply_mark(&mut expr, top_level_mark);\n        expr\n    })\n    .unwrap_or_else(|()| {\n        panic!(\n            \"failed to parse jsx option {}: '{}' is not an expression\",\n            name, fm.src,\n        )\n    })\n}\n\nfn apply_mark(e: &mut Expr, mark: Mark) {\n    match e {\n        Expr::Ident(i) => {\n            i.ctxt = i.ctxt.apply_mark(mark);\n        }\n        Expr::Member(MemberExpr { obj, .. }) => {\n            apply_mark(obj, mark);\n        }\n        _ => {}\n    }\n}\n","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_react/src/jsx/mod.rs#L155-L191","documentation":"parse_expr_for_jsx (crates/swc_ecma_transforms_react/src/jsx/mod.rs:143) parses the strings used as JSX pragmas into an expression AST via parse_file_as_expr before the JSX transform runs. If the string is not a single valid JavaScript expression (a statement, empty string, unbalanced bracket, stray comma or call parens), parsing fails and the function panics with the option name and the raw string. It is used for the `pragma` and `pragmaFrag` config options (jsc.transform.react) and for `/** @jsx */` / `/** @jsxFrag */` docblock comments.","triggerScenarios":"Setting jsc.transform.react.pragma or pragmaFrag to a non-expression string such as \"React.createElement(\", \"\", \"a,\", \"import x from 'y'\", or a comment pragma value (module-jsx-pragma / module-jsx-pragma-frag paths at jsx/mod.rs:379 and :394) that fails to parse.","commonSituations":"Typos or trailing punctuation in .swcrc / next.config.js compiler options; migrating a Babel config where the pragma looked like a call (\"h()\"); environment-variable interpolation producing an empty pragma string.","solutions":["Use a plain identifier or member expression: \"React.createElement\", \"h\", \"Vue.h\" (and \"React.Fragment\" for pragmaFrag).","Remove call parens/arguments — the pragma names a function, it is never invoked.","If the value comes from a `/** @jsx */` comment pragma, fix or delete that comment line."],"exampleFix":"// before (.swcrc)\n{\n  \"jsc\": { \"transform\": { \"react\": { \"pragma\": \"React.createElement(\" } } }\n}\n\n// after\n{\n  \"jsc\": { \"transform\": { \"react\": { \"pragma\": \"React.createElement\" } } }\n}","handlingStrategy":"validation","validationCode":"// Validate a pragma string BEFORE constructing the react transform.\nfn assert_valid_pragma(cm: &SourceMap, name: &str, src: &str) -> Result<(), String> {\n    let fm = cm.new_source_file(SourceFile::new(), src.into());\n    let mut errors = Vec::new();\n    let ok = swc_ecma_parser::parse_file_as_expr(\n        &fm, Syntax::default(), Default::default(), None, &mut errors,\n    ).is_ok();\n    if ok && errors.is_empty() { Ok(()) } else {\n        Err(format!(\"option {name}: {src:?} is not a valid expression\"))\n    }\n}","typeGuard":null,"tryCatchPattern":"// Pass construction panics before any file is processed; wrap config load:\nmatch std::panic::catch_unwind(|| jsx(cm.clone(), comments, options, m1, m2)) {\n    Ok(pass) => Ok(pass),\n    Err(payload) => Err(anyhow!(\"invalid react pragma config: {payload:?}\")),\n}","preventionTips":["Keep pragma values as plain identifiers/member expressions (\"h\", \"React.createElement\", \"React.Fragment\").","Never include call parens, arguments, or statements in pragma/pragmaFrag.","If pragmas come from env vars, validate they are non-empty at config load time."],"tags":["swc","jsx","react","pragma","config","panic"],"backgroundTag":"invalid-compiler-config-value","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}