tailwindlabs/tailwindcss · error · Error

The --spacing(…) function only accepts a single argument, bu

Error message

The --spacing(…) function only accepts a single argument, but received ${rest.length + 1}.

What it means

Thrown by the `--spacing(...)` handler when more than one argument is supplied (`rest.length > 0`). `--spacing` accepts a single multiplier value only, so extra comma-separated arguments are rejected. The error message interpolates the actual count via `rest.length + 1` so the user sees the real number received.

Source

Thrown at packages/tailwindcss/src/css-functions.ts:54

      `The --alpha(…) function only accepts one argument, e.g.: \`--alpha(${color || 'var(--my-color)'} / ${alpha || '50%'})\``,
    )
  }

  return withAlpha(color, alpha)
}

function spacing(
  designSystem: DesignSystem,
  _source: AstNode,
  value: string,
  ...rest: string[]
): string {
  if (!value) {
    throw new Error(`The --spacing(…) function requires an argument, but received none.`)
  }

  if (rest.length > 0) {
    throw new Error(
      `The --spacing(…) function only accepts a single argument, but received ${rest.length + 1}.`,
    )
  }

  let multiplier = designSystem.theme.resolve(null, ['--spacing'])
  if (!multiplier) {
    throw new Error(
      'The --spacing(…) function requires that the `--spacing` theme variable exists, but it was not found.',
    )
  }

  // Optimization:
  //
  // - We know that at this point the `--spacing` value must be set.
  // - We know that `--spacing` must be set to a `<length>` unit, such as `0.25rem`
  // - We can assume that the `--spacing` value is not set to a `0`-like value.
  //   Otherwise `p-<anything>` would calculate as `0` which wouldn't make sense.
  //

View on GitHub (pinned to 16e94cbf7f)

Solutions

  1. Pass exactly one argument, e.g. `--spacing(4)`.
  2. If you intended a fallback, wrap at the CSS level: `var(--spacing(4), 1rem)` is not supported — instead compute the fallback outside the function.
  3. For multi-value spacing use separate `--spacing(...)` calls or a `calc()` expression.

Example fix

/* before */
.x { padding: --spacing(4, 2); }
/* after */
.x { padding: --spacing(4); }
Defensive patterns

Strategy: validation

Validate before calling

function assertSingleSpacingArg(inner: string): void {
  const count = inner.split(',').length;
  if (count > 1) throw new Error(`--spacing got ${count} args, expected 1`);
}

Type guard

function isSingleSpacingArgument(inner: string): boolean {
  return inner.split(',').length === 1;
}

Prevention

When it happens

Trigger: Writing `--spacing(4, 2)`, `--spacing(1rem, fallback)`, or any call where the function parser produces trailing top-level arguments beyond the first.

Common situations: Assuming `--spacing` supports a fallback like `var()`; copy-paste from `clamp(min, pref, max)` patterns; trailing comma.

Related errors


AI-assisted analysis of tailwindlabs/tailwindcss@16e94cbf7f (2026-08-12). Data as JSON: /api/errors/1ce99047be2818dd. Report an issue: GitHub.