denoland/deno · error · syn::Error

Unit fields are currently not supported

Error message

Unit fields are currently not supported

What it means

#[derive(FromV8)] on a struct matches on Fields; named and unnamed (tuple) fields are converted from V8 objects/arrays, but Fields::Unit — a fieldless unit struct like struct Marker; — is rejected. There is no V8 value shape the derive maps a unit struct to, so it fails at compile time instead of generating a stub.

Source

Thrown at libs/ops/conversion/from_v8/struct.rs:141

                let __element_value = __array.get_index(__scope, #i).ok_or_else(|| ::deno_error::JsErrorBox::type_error(concat!("Missing element ", #i, " on '", #ident_string, "'")))?;
                #converter
              }
            }
          })
          .collect::<Vec<_>>();

        quote! {
          let __array = ::deno_core::v8::Local::<::deno_core::v8::Array>::try_from(__value)
            .map_err(|err| ::deno_error::JsErrorBox::from_err(::deno_core::error::DataError::from(err)))?;

          Ok(Self(#(#fields),*))
        }
      };

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

struct StructField {
  name: Ident,
  js_name: Ident,
  default_value: Option<Expr>,
  serde: bool,
  ty: Type,
}

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

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Give the type a real payload, e.g. turn it into a newtype struct Empty(()) or add a field, so the derive has something to convert.
  2. Remove the FromV8 derive — a unit type never crosses the V8 boundary as data; pass nothing (or a plain op with no args) instead.
  3. If it must appear in signatures, write a manual FromV8 impl that accepts any value and ignores it.

Example fix

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

// after
#[derive(FromV8)]
struct Marker(Option<serde_json::Value>); // or drop the derive entirely
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Deriving FromV8 on a unit struct: #[derive(FromV8)] struct Empty; (also struct Empty {} is a named-fields struct with zero fields — the truly rejected form is the unit struct with no braces).

Common situations: Marker/phantom types accidentally swept into an op module's derive list; refactoring a struct down to zero fields and leaving the derive on; generating derives via a macro that applies them uniformly.

Related errors


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