swc-project/swc · error
unable to access unknown nodes
Error message
unable to access unknown nodes
What it means
This Babelify impl maps an ImportSpecifier (named, default, or namespace import) to the corresponding Babel specifier type. The `#[cfg(swc_ast_unknown)]` wildcard is compiled only in builds passing `--cfg=swc_ast_unknown` (the cfg SWC plugin builds use to mark swc_ecma_ast enums non_exhaustive for cross-version tolerance). Hitting the panic means the ImportSpecifier value carries a variant the linked swc_ecma_ast version does not define — i.e. the AST came from a different swc version than the one compiled in.
Source
Thrown at crates/swc_estree_compat/src/babelify/module_decl.rs:267
// map cleanly to
// TsInterfaceDecl
// expected by swc
#[cfg(swc_ast_unknown)]
_ => panic!("unable to access unknown nodes"),
}
}
}
impl Babelify for ImportSpecifier {
type Output = ImportSpecifierType;
fn babelify(self, ctx: &Context) -> Self::Output {
match self {
ImportSpecifier::Named(s) => ImportSpecifierType::Import(s.babelify(ctx)),
ImportSpecifier::Default(s) => ImportSpecifierType::Default(s.babelify(ctx)),
ImportSpecifier::Namespace(s) => ImportSpecifierType::Namespace(s.babelify(ctx)),
#[cfg(swc_ast_unknown)]
_ => panic!("unable to access unknown nodes"),
}
}
}
impl Babelify for ImportDefaultSpecifier {
type Output = BabelImportDefaultSpecifier;
fn babelify(self, ctx: &Context) -> Self::Output {
BabelImportDefaultSpecifier {
base: ctx.base(self.span),
local: self.local.babelify(ctx),
}
}
}
impl Babelify for ImportStarAsSpecifier {
type Output = ImportNamespaceSpecifier;
View on GitHub (pinned to 5176682b65)
Solutions
- Unify versions: `cargo tree -i swc_ecma_ast` should list exactly one; depend via swc_core
- Upgrade swc_estree_compat in the same change as swc_ecma_ast so new specifier variants are handled
- Rebuild the plugin/wasm boundary with the host's swc version
- Use catch_unwind around babelify to fail per-file while versions are migrated
Defensive patterns
Strategy: try-catch
Type guard
fn import_specifier_known(s: &ImportSpecifier) -> bool {
matches!(s, ImportSpecifier::Named(_) | ImportSpecifier::Default(_) | ImportSpecifier::Namespace(_))
} Try / catch
let out = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| program.babelify(&ctx)))
.map_err(|_| anyhow::anyhow!("babelify failed: swc_ecma_ast version mismatch (unknown ImportSpecifier)"))?; Prevention
- Enforce a single swc_ecma_ast version in the dependency graph
- Rebuild plugin/wasm artifacts with each host swc upgrade
- Track swc release notes for new specifier variants
- Smoke-test babelify on import-heavy fixtures after upgrades
When it happens
Trigger: Babelifying import statements whose specifier enum arrived from a newer/older swc_ecma_ast — across a plugin ABI boundary, a mixed-version Cargo graph, or AST deserialization from a different producer version.
Common situations: Plugin/wasm artifacts built against an older swc_core running on a newer host; partial swc upgrades; duplicate swc_ecma_ast versions resolved through different dependency paths.
Related errors
- unable to access unknown nodes
- unable to access unknown nodes
- unable to access unknown nodes
- unable to access unknown nodes
- unable to access unknown nodes
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/a9a02bab0137cc36.
Report an issue: GitHub.