If a theme variable doesn’t exist and no fallback is provided:
.element { color: theme(--color-missing);}
Error:
Could not resolve value for theme function: `theme(--color-missing)`.Consider checking if the variable name is correct or provide a fallback value to silence this error.
Modern syntax requires CSS custom property names (starting with --):
/* ❌ Invalid */.element { color: theme(primary);}/* Error: The theme() function can only be used with CSS variables *//* ✅ Valid */.element { color: theme(--color-primary);}
From the source code (css-functions.ts:68-127), the theme() function:
Validates the variable name starts with --
Checks for the inline modifier
Auto-inlines if used in an at-rule
Resolves the value from the design system
Handles fallback values
Injects fallbacks into nested var() or theme() calls
function theme( designSystem: DesignSystem, source: AstNode, path: string, ...fallback: string[]): string { if (!path.startsWith('--')) { throw new Error( `The --theme(…) function can only be used with CSS variables from your theme.` ) } let inline = false // Handle inline modifier if (path.endsWith(' inline')) { inline = true path = path.slice(0, -7) } // Auto-inline in at-rules if (source.kind === 'at-rule') { inline = true } let resolvedValue = designSystem.resolveThemeValue(path, inline) if (!resolvedValue) { if (fallback.length > 0) return fallback.join(', ') throw new Error( `Could not resolve value for theme function: \`theme(${path})\`` ) } // Handle fallback injection if (fallback.length > 0) { // ... fallback handling logic } return resolvedValue}