{"record":{"id":"48ceaa6cec6e6d81","repo":"swc-project/swc","slug":"unable-to-access-unknown-nodes","errorCode":null,"errorMessage":"unable to access unknown nodes","messagePattern":"unable to access unknown nodes","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_estree_compat/src/babelify/expr.rs","lineNumber":175,"sourceCode":"            ),\n            Expr::TsConstAssertion(_) => panic!(\n                \"illegal conversion: Cannot convert {:?} to ExprOutput - babel has no equivalent\",\n                &self\n            ),\n            Expr::TsSatisfies(_) => panic!(\n                \"illegal conversion: Cannot convert {:?} to ExprOutput - babel has no equivalent\",\n                &self\n            ),\n            Expr::OptChain(_) => panic!(\n                \"illegal conversion: Cannot convert {:?} to ExprOutput - babel has no equivalent\",\n                &self\n            ),\n            Expr::Invalid(_) => panic!(\n                \"illegal conversion: Cannot convert {:?} to ExprOutput - babel has no equivalent\",\n                &self\n            ),\n            #[cfg(swc_ast_unknown)]\n            _ => panic!(\"unable to access unknown nodes\"),\n        }\n    }\n}\n\nimpl From<ExprOutput> for Expression {\n    fn from(o: ExprOutput) -> Self {\n        match o {\n            ExprOutput::Expr(expr) => *expr,\n            ExprOutput::Private(_) => panic!(\n                \"illegal conversion: Cannot convert {:?} to Expression - babel has no equivalent\",\n                &o\n            ),\n        }\n    }\n}\n\nimpl From<ExprOutput> for BinaryExprLeft {\n    fn from(o: ExprOutput) -> Self {","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_estree_compat/src/babelify/expr.rs#L157-L193","documentation":"swc_ecma_ast can be built with `--cfg=swc_ast_unknown`, which adds `Unknown` variants to AST enums for forward compatibility with plugin hosts (see crates/swc_plugin_backend_tests/tests/fixture/.cargo/config.toml). Under that cfg, every exhaustive match in swc_estree_compat carries an `_ => panic!(\"unable to access unknown nodes\")` arm (expr.rs:175 for Expr); it fires when the AST actually contains an Unknown node, i.e. the AST came from a different swc_ecma_ast version than the converter was compiled against.","triggerScenarios":"Building swc crates with rustflags = [\"--cfg=swc_ast_unknown\"] and babelifying an AST containing Unknown variants — typically deserialized from a plugin/host process whose swc_ecma_ast/swc_core version differs from swc_estree_compat's.","commonSituations":"SWC plugin development where plugin and host crate versions drift; CI configurations enabling the cfg globally; mixing published swc crate versions in one dependency graph.","solutions":["For normal (non-plugin) builds, drop `--cfg=swc_ast_unknown` from RUSTFLAGS so the arm is compiled out.","Align swc_ecma_ast / swc_core versions between the AST producer and swc_estree_compat so no Unknown nodes exist.","If you must run under the cfg, reject Unknown nodes at your boundary before calling babelify."],"exampleFix":"# before: .cargo/config.toml\n[build]\nrustflags = [\"--cfg=swc_ast_unknown\"]\n\n# after\n[build]\nrustflags = []","handlingStrategy":"validation","validationCode":"// When running under --cfg=swc_ast_unknown, screen deserialized ASTs first.\n#[cfg(swc_ast_unknown)]\nfn has_unknown_expr(program: &Program) -> bool {\n    struct Scan(bool);\n    impl Visit for Scan {\n        fn visit_expr(&mut self, e: &Expr) {\n            if matches!(e, Expr::Unknown(_)) { self.0 = true; }\n            e.visit_children_with(self);\n        }\n    }\n    let mut s = Scan(false);\n    program.visit_with(&mut s);\n    s.0\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not set `--cfg=swc_ast_unknown` in normal builds; reserve it for plugin-runtime builds.","Keep swc_ecma_ast/swc_core versions identical between AST producers and swc_estree_compat.","Automate a version-alignment check in CI for plugin projects."],"tags":["swc","estree","build-config","version-mismatch","plugins","panic"],"backgroundTag":"unknown-ast-node-variant","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}