swc-project/swc · error
Expected string token
Error message
Expected string token
What it means
Fired while parsing a Str (CSS string): the current token was not a String token, so no quoted string value could be produced. This `if !is!(self, "string")` check is a validation guard; input at fault is a string-required context (e.g. font family, content value, @import href) receiving an unquoted identifier or other token.
Source
Thrown at crates/swc_css_parser/src/parser/values_and_units/mod.rs:2570
Ok(Percentage { span, value })
}
_ => {
unreachable!()
}
}
}
}
impl<I> Parse<Str> for Parser<I>
where
I: ParserInput,
{
fn parse(&mut self) -> PResult<Str> {
let span = self.input.cur_span();
if !is!(self, "string") {
return Err(Error::new(span, ErrorKind::Expected("string token")));
}
match bump!(self) {
Token::String { value, raw } => Ok(Str {
span,
value,
raw: Some(raw),
}),
_ => {
unreachable!()
}
}
}
}
impl<I> Parse<Url> for Parser<I>
where
I: ParserInput,View on GitHub (pinned to 5176682b65)
Solutions
- Wrap the value in quotes ('...' or "...") to make it a string
- Use an Ident parser if an unquoted identifier was intended
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at crates/swc_css_parser/src/parser/values_and_units/mod.rs:2570 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/8bd21702e59efd89.
Report an issue: GitHub.