leptos-rs/leptos · error

`encoding` and `output` should not both be specified

Error message

`encoding` and `output` should not both be specified

What it means

The #[server] macro parser errors when both `encoding` and `output` are specified. They configure the same concern — how the response body is serialized — via different mechanisms (built-in encoding vs. custom output type), so combining them is ambiguous and fails at compile time.

Source

Thrown at server_fn_macro/src/lib.rs:1127

                        }
                        fn_path = Some(stream.parse()?);
                    } else if key == "input" {
                        if encoding.is_some() {
                            return Err(syn::Error::new(
                                key.span(),
                                "`encoding` and `input` should not both be \
                                 specified",
                            ));
                        } else if input.is_some() {
                            return Err(syn::Error::new(
                                key.span(),
                                "keyword argument repeated: `input`",
                            ));
                        }
                        input = Some(stream.parse()?);
                    } else if key == "input_derive" {
                        if input_derive.is_some() {
                            return Err(syn::Error::new(
                                key.span(),
                                "keyword argument repeated: `input_derive`",
                            ));
                        }
                        input_derive = Some(stream.parse()?);
                    } else if key == "output" {
                        if encoding.is_some() {
                            return Err(syn::Error::new(
                                key.span(),
                                "`encoding` and `output` should not both be \
                                 specified",
                            ));
                        } else if output.is_some() {
                            return Err(syn::Error::new(
                                key.span(),
                                "keyword argument repeated: `output`",
                            ));
                        }

View on GitHub (pinned to 32d20f6c9d)

Solutions

  1. Remove `encoding = ...` and keep `output = ...` for a custom output type.
  2. Or remove `output` and keep `encoding` to use a built-in encoding.
  3. Remember the same rule applies to `input`: it cannot coexist with `encoding`.

Example fix

// before
#[server(encoding = "Json", output = MyOutput)]
async fn load() -> Result<MyOutput, ServerFnError> { todo!() }

// after
#[server(output = MyOutput)]
async fn load() -> Result<MyOutput, ServerFnError> { todo!() }
Defensive patterns

Strategy: validation

Validate before calling

// Reject attributes mixing `encoding` with `output`:
// grep -rnE '#\[server\([^)\n]*encoding[^)\n]*output\s*=' src/ && exit 1 || exit 0

Prevention

When it happens

Trigger: Writing #[server(encoding = "...", output = ...)] in one attribute, typically after migrating from the encoding API to custom output types without removing `encoding`.

Common situations: Upgrading server_fn/leptos across versions where `output` was introduced; mixing doc examples; leaving both args after an LLM-assisted or manual refactor.

Related errors


AI-assisted analysis of leptos-rs/leptos@32d20f6c9d (2026-09-01). Data as JSON: /api/errors/2d9ec3424905e41c. Report an issue: GitHub.