swc-project/swc · error

unable to access unknown nodes

Error message

unable to access unknown nodes

What it means

babelify maps each SWC binding-pattern kind (Ident, Array, Rest, Object, Assign, Expr) to a PatOutput; the `_` arm exists only under the `swc_ast_unknown` cfg and panics on any pattern variant this build of swc_estree_compat does not recognize. It indicates the AST was produced by a swc_ecma_ast whose Pat enum is newer than the converter.

Source

Thrown at crates/swc_estree_compat/src/babelify/pat.rs:41

}

impl Babelify for Pat {
    type Output = PatOutput;

    fn babelify(self, ctx: &Context) -> Self::Output {
        match self {
            Pat::Ident(i) => PatOutput::Id(i.babelify(ctx)),
            Pat::Array(a) => PatOutput::Array(a.babelify(ctx)),
            Pat::Rest(r) => PatOutput::Rest(r.babelify(ctx)),
            Pat::Object(o) => PatOutput::Object(o.babelify(ctx)),
            Pat::Assign(a) => PatOutput::Assign(a.babelify(ctx)),
            Pat::Expr(e) => PatOutput::Expr(Box::alloc().init(e.babelify(ctx).into())),
            Pat::Invalid(_) => panic!(
                "illegal conversion: Cannot convert {:?} to PatOutput",
                &self
            ),
            #[cfg(swc_ast_unknown)]
            _ => panic!("unable to access unknown nodes"),
        }
    }
}

impl From<PatOutput> for Pattern {
    fn from(pat: PatOutput) -> Self {
        match pat {
            PatOutput::Assign(a) => Pattern::Assignment(a),
            PatOutput::Array(a) => Pattern::Array(a),
            PatOutput::Object(o) => Pattern::Object(o),
            _ => panic!("illegal conversion: Cannot convert {:?} to Pattern", &pat),
        }
    }
}

impl From<PatOutput> for ObjectPropVal {
    fn from(pat: PatOutput) -> Self {
        match pat {

View on GitHub (pinned to 5176682b65)

Solutions

  1. Build the estree-conversion binary without `--cfg=swc_ast_unknown`
  2. Unify swc crate versions on one swc_core release
  3. Cross boundaries via serialization so unknown variants fail at decode
  4. Add the missing Pat arm in pat.rs upstream

Example fix

# before
RUSTFLAGS="--cfg=swc_ast_unknown" cargo build

# after
cargo build
Defensive patterns

Strategy: validation

Validate before calling

#[cfg(swc_ast_unknown)]
compile_error!("babelify panics on Unknown Pat nodes; build without --cfg=swc_ast_unknown");

Try / catch

use std::panic::{catch_unwind, AssertUnwindSafe};

let estree = catch_unwind(AssertUnwindSafe(|| program.babelify()))
    .map_err(|p| anyhow!("babelify panicked: {:?}", p))?;

Prevention

When it happens

Trigger: Babelify a pattern node carrying an Unknown/newly added Pat variant in a build with `--cfg=swc_ast_unknown` — e.g. a plugin host converting an AST from a newer swc version, or a fork adding a pattern kind without a babelify arm.

Common situations: Plugin builds (cfg auto-set by plugin .cargo/config.toml), dependency drift between swc_ecma_ast and swc_estree_compat, deserializing foreign ASTs into the converter.

Related errors


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/9513918fe5ccee60. Report an issue: GitHub.