{"record":{"id":"632dc5927c387563","repo":"tailwindlabs/tailwindcss","slug":"the-spacing-function-requires-that-the-spa","errorCode":null,"errorMessage":"The --spacing(…) function requires that the `--spacing` theme variable exists, but it was not found.","messagePattern":"The --spacing\\(…\\) function requires that the `--spacing` theme variable exists, but it was not found\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/tailwindcss/src/css-functions.ts","lineNumber":61,"sourceCode":"function spacing(\n  designSystem: DesignSystem,\n  _source: AstNode,\n  value: string,\n  ...rest: string[]\n): string {\n  if (!value) {\n    throw new Error(`The --spacing(…) function requires an argument, but received none.`)\n  }\n\n  if (rest.length > 0) {\n    throw new Error(\n      `The --spacing(…) function only accepts a single argument, but received ${rest.length + 1}.`,\n    )\n  }\n\n  let multiplier = designSystem.theme.resolve(null, ['--spacing'])\n  if (!multiplier) {\n    throw new Error(\n      'The --spacing(…) function requires that the `--spacing` theme variable exists, but it was not found.',\n    )\n  }\n\n  // Optimization:\n  //\n  // - We know that at this point the `--spacing` value must be set.\n  // - We know that `--spacing` must be set to a `<length>` unit, such as `0.25rem`\n  // - We can assume that the `--spacing` value is not set to a `0`-like value.\n  //   Otherwise `p-<anything>` would calculate as `0` which wouldn't make sense.\n  //\n  // - That means that a value of `0` can be replaced by `0px`. It's important\n  //   to keep the unit so the value stays a `<length>`, e.g. when assigned to\n  //   a custom property and later used inside `calc(…)`.\n  // - That means that a value of `1` can be replaced by `multiplier`\n  let valueDimension = dimensions.get(value)\n  if (valueDimension) {\n    if (valueDimension[0] === 0) return '0px'","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/tailwindlabs/tailwindcss/blob/16e94cbf7f965c5ad697e90e940b5e178efad67c/packages/tailwindcss/src/css-functions.ts#L43-L79","documentation":"Thrown by the `--spacing(...)` handler after argument validation succeeds but the theme lookup `designSystem.theme.resolve(null, ['--spacing'])` returns a falsy value. The `--spacing` base variable is the engine of all spacing utilities (`p-*`, `m-*`, `gap-*`, etc.); if it is absent the multiplier cannot be computed. This typically means the default theme was removed or overridden without redefining `--spacing`.","triggerScenarios":"A `@theme` block that clears defaults (e.g. `--spacing: initial;`) without redefining `--spacing`; disabling the default theme import; a custom design system built without the spacing scale; calling `--spacing(4)` in a context where the theme was built in reference-only mode missing the variable.","commonSituations":"Replacing Tailwind's default theme wholesale and forgetting `--spacing`; using `@theme reference` only; upgrading a config that previously relied on `theme.spacing` being implicitly present.","solutions":["Define `--spacing` in your `@theme` block, e.g. `@theme { --spacing: 0.25rem; }`.","If you used `--spacing: initial` to clear it, re-add a concrete length afterward.","Ensure the default `theme.css` (which ships `--spacing: 0.25rem`) is still imported by your entry CSS.","Avoid calling `--spacing(...)` directly in custom CSS if your theme intentionally omits the variable; use explicit lengths instead."],"exampleFix":"/* before */\n@theme {\n  --spacing: initial;\n}\n.x { padding: --spacing(4); }\n/* after */\n@theme {\n  --spacing: 0.25rem;\n}\n.x { padding: --spacing(4); }","handlingStrategy":"validation","validationCode":"// Ensure the --spacing variable is defined in the theme before using --spacing()\nfunction ensureSpacingTheme(themeCss: string): boolean {\n  return /--spacing\\s*:/.test(themeCss);\n}\nif (!ensureSpacingTheme(myTheme)) {\n  throw new Error('Add `--spacing: 0.25rem;` to your @theme block');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always define --spacing in your @theme (the default theme ships 0.25rem).","Do not use `--spacing: initial` without re-adding a concrete length.","Keep the default theme.css import unless you fully replace --spacing."],"tags":["tailwind-v4","css-function","spacing","theme","config"],"backgroundTag":null,"analyzedSha":"16e94cbf7f965c5ad697e90e940b5e178efad67c","analyzedAt":"2026-08-12T06:02:42.469Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}