swc-project/swc · error

Boolean logic in @custom-media at-rules is not supported by…

Error message

Boolean logic in @custom-media at-rules is not supported by swc

What it means

A capability guard in the @custom-media processing pass (swc_css_compat custom_media.rs:242). When a media query references a custom media whose definition contains boolean logic (and/or/not over custom media), the pass attempts to splice that logic into the referencing query; splicing arbitrary boolean conditions is not supported by swc's implementation, so the pass aborts with this marker when it would need to inline such a condition.

Solutions

  1. Rewrite the @custom-media definition to avoid boolean logic (single custom media per definition)
  2. Inline the media condition manually in the stylesheet instead of relying on @custom-media
  3. Check for a swc_css_compat version that supports boolean-logic custom media splicing
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at crates/swc_css_compat/src/compiler/custom_media.rs:242 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at crates/swc_css_compat/src/compiler/custom_media.rs:242

        }
    }

    pub(crate) fn process_media_in_parens(&mut self, n: &MediaInParens) -> Option<MediaInParens> {
        if let Some(MediaFeatureBoolean {
            name: MediaFeatureName::ExtensionName(name),
            ..
        }) = n.as_feature().and_then(|feature| feature.as_boolean())
        {
            if let Some(custom_media) = self.medias.iter().find(|m| m.name.value == name.value) {
                let mut new_media_condition = MediaCondition {
                    span: DUMMY_SP,
                    conditions: Vec::new(),
                };

                let queries = match &custom_media.media {
                    CustomMediaQueryMediaType::Ident(_) => {
                        // TODO make me warning, we should keep code as is in such cases
                        unimplemented!(
                            "Boolean logic in @custom-media at-rules is not supported by swc"
                        );
                    }
                    CustomMediaQueryMediaType::MediaQueryList(media_query_list) => {
                        &media_query_list.queries
                    }
                };

                for query in queries {
                    if query.media_type.is_some() || query.modifier.is_some() {
                        // TODO throw a warning on multiple media types
                        self.modifier_and_media_type =
                            Some((query.modifier.clone(), query.media_type.clone()));
                    }

                    if let Some(condition) = &query.condition {
                        match &**condition {
                            MediaConditionType::All(media_condition) => {

View on GitHub (pinned to 5176682b65)