swc-project/swc · error

Not supported yet

Error message

Not supported yet

What it means

TransformPluginProgramMetadata::get_raw_experimental_context in swc_plugin_proxy is deliberately unimplemented: a TODO comment states there is no clear use case yet, and the unimplemented!("Not supported yet") sits before both the wasm32 host-call return and the native fallback, so the function panics on every target. Unlike its siblings (get_transform_plugin_config, get_context, get_experimental_context) which return real values on wasm32 and None on native, this bulk-HashMap accessor has no working path at all.

Source

Thrown at crates/swc_plugin_proxy/src/metadata/transform_plugin_metadata.rs:106

            let (key_ptr, key_ptr_len) = serialized.as_ptr();
            __copy_context_key_to_host_env(key_ptr as u32, key_ptr_len as u32);

            __get_experimental_transform_context(serialized_ptr)
        });

        #[cfg(not(target_arch = "wasm32"))]
        None
    }

    /// Returns experimental metadata context, but returns whole value as a
    /// HashMap.
    ///
    /// Each time this is called, it'll require a call between host-plugin which
    /// involves serialization / deserialization.
    #[allow(unreachable_code)]
    pub fn get_raw_experimental_context(&self) -> swc_common::plugin::metadata::Context {
        // TODO: There is no clear usecase yet - enable when we have a correct usecase.
        unimplemented!("Not supported yet");

        #[cfg(target_arch = "wasm32")]
        return read_returned_result_from_host(|serialized_ptr| unsafe {
            __get_raw_experiemtal_transform_context(serialized_ptr)
        })
        .expect("Raw experimental metadata should exists, even if it's empty map");

        #[cfg(not(target_arch = "wasm32"))]
        swc_common::plugin::metadata::Context(rustc_hash::FxHashMap::default())
    }
}

View on GitHub (pinned to 5176682b65)

Solutions

  1. Use get_experimental_context(key) per key instead — it is implemented and returns Option<String> on wasm32.
  2. If you need several keys, enumerate the known keys and call get_experimental_context for each.
  3. Upstream an implementation in crates/swc_plugin_proxy/src/metadata/transform_plugin_metadata.rs (the host import __get_raw_experiemtal_transform_context already exists) if the bulk API is required.

Example fix

// before: always panics — TODO'd out upstream
let all: Context = metadata.get_raw_experimental_context();

// after: use the implemented per-key API
for key in ["cacheKey", "envs", "globals"] {
    if let Some(v) = metadata.get_experimental_context(key) {
        handle(key, v);
    }
}
Defensive patterns

Strategy: fallback

Try / catch

// Rust: the API panics (not a Result); if you must isolate it, contain and fall back
let raw = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
    metadata.get_raw_experimental_context()
}));
let value = raw.ok().or_else(|| metadata.get_experimental_context(key));

Prevention

When it happens

Trigger: Calling metadata.get_raw_experimental_context() anywhere — inside a plugin transform (wasm32 guest) or in host-side code/tests that construct TransformPluginProgramMetadata.

Common situations: Plugin authors assuming the 'raw' variant of the experimental-context API mirrors get_experimental_context; copying swc_core internal call sites; upgrading swc_core versions where experimental metadata APIs shifted.

Related errors


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