denoland/deno · error · syn::Error

Unit fields are currently not supported

Error message

Unit fields are currently not supported

What it means

The ToV8 struct body generator matches on the struct's Fields: named fields become a V8 object, unnamed fields become a V8 array, and Fields::Unit is rejected with this compile error. A unit struct has neither an object nor an array shape, so the derive refuses instead of inventing one.

Source

Thrown at libs/ops/conversion/to_v8/struct.rs:150

      } else {
        let fields = fields
          .into_iter()
          .map(|field| {
            let i = format_ident!("__{}", field.i, span = field.span);
            convert_or_serde(field.serde, field.span, i)
          })
          .collect::<Vec<_>>();

        quote! {
          let __value = &[#(#fields),*];
          Ok::<_, ::deno_error::JsErrorBox>(::deno_core::v8::Array::new_with_elements(__scope, __value).into())
        }
      };

      Ok(value)
    }
    Fields::Unit => {
      Err(Error::new(span, "Unit fields are currently not supported"))
    }
  }
}

pub struct StructField {
  pub name: Ident,
  serde: bool,
  skip_if: Option<Path>,
  ty: Type,
  pub js_name: Ident,
}

impl TryFrom<Field> for StructField {
  type Error = Error;
  fn try_from(value: Field) -> Result<Self, Self::Error> {
    let span = value.span();
    let crate::conversion::SharedAttribute {
      mut rename,

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Delete the derive — the simplest correct fix for a data-less type.
  2. Convert the type to carry a field (struct Flag(bool)) or become a newtype so ToV8 has a value to emit.
  3. Return v8::Global/undefined from a manual impl if JS only needs a placeholder.

Example fix

// before
#[derive(ToV8)]
struct Flag; // error: Unit fields are currently not supported

// after
#[derive(ToV8)]
struct Flag(bool);
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Deriving ToV8 on a unit struct declaration (no fields, no braces), e.g. #[derive(ToV8)] struct Flag;.

Common situations: Bulk-adding derives via IDE quick-fixes or a shared derive macro that hits marker types; leftover derives after a struct was emptied out.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/e61bc9ddf058bcce. Report an issue: GitHub.