tailwindlabs/tailwindcss · error · TypeError
`CSS.escape` requires an argument.
Error message
`CSS.escape` requires an argument.
What it means
Thrown by escape() in escape.ts to mirror the native CSS.escape() Web API, which requires exactly one argument. The check uses arguments.length === 0 so it fires only when the function is called with no arguments at all — not when undefined is passed (undefined gets coerced to the string 'undefined'). It is a TypeError, not a generic Error, matching the spec.
Source
Thrown at packages/tailwindcss/src/utils/escape.ts:4
// https://drafts.csswg.org/cssom/#serialize-an-identifier
export function escape(value: string) {
if (arguments.length === 0) {
throw new TypeError('`CSS.escape` requires an argument.')
}
let string = String(value)
let length = string.length
let index = -1
let codeUnit: number
let result = ''
let firstCodeUnit = string.charCodeAt(0)
if (
// If the character is the first character and is a `-` (U+002D), and
// there is no second character, […]
length === 1 &&
firstCodeUnit === 0x002d
) {
return '\\' + string
}
while (++index < length) {View on GitHub (pinned to 16e94cbf7f)
Solutions
- Pass the identifier string: escape('my-class').
- If the value may be absent, guard the call: value !== undefined && escape(value).
- Prefer TypeScript to catch missing-argument calls at compile time (the signature is escape(value: string)).
Example fix
// before — throws at runtime
let id = escape()
// after
let id = escape('my-class') Defensive patterns
Strategy: type-guard
Validate before calling
if (arguments.length === 0 || value === undefined) {
throw new TypeError('escape requires a value')
}
escape(value) Type guard
function isEscapable(value: unknown): value is string {
return typeof value === 'string'
} Prevention
- Rely on TypeScript's type system to prevent zero-argument calls.
- Audit call sites when refactoring to ensure the argument survives.
- Avoid apply/call patterns that can drop the argument.
When it happens
Trigger: Calling escape() with no arguments: escape(). Calling it via apply/call with an empty array. Destructuring or spreading that accidentally drops the argument.
Common situations: Refactoring a call site and dropping the argument. Using .map(escape) on an array that contains holes or is unexpectedly empty in a way that bypasses the argument (note: .map(escape) actually passes the element, so this is safe; the real trigger is a bare escape()).
Related errors
- Invalid theme value `${value}` for namespace `${key}`
- The pattern `${pattern}` is not balanced.
- Step cannot be zero in sequence expansion.
- Cannot use `@variant` with empty variant
- Cannot use `@variant` with unknown variant: ${variant}
AI-assisted analysis of tailwindlabs/tailwindcss@16e94cbf7f (2026-08-12).
Data as JSON: /api/errors/6eb6ff33e3c0b09a.
Report an issue: GitHub.