swc-project/swc · error
Expected url or function (with 'url' or 'src' name) token
Error message
Expected url or function (with 'url' or 'src' name) token
What it means
Fired while parsing a Url: the current token was neither a url(...) token nor a Function token, so no URL value could be produced. This `if !is_one_of!(self, Url, Function)` check is a validation guard; input at fault is a url-required context (e.g. @import, background-image) receiving a bare ident or string instead of `url(...)`.
Source
Thrown at crates/swc_css_parser/src/parser/values_and_units/mod.rs:2594
value,
raw: Some(raw),
}),
_ => {
unreachable!()
}
}
}
}
impl<I> Parse<Url> for Parser<I>
where
I: ParserInput,
{
fn parse(&mut self) -> PResult<Url> {
let span = self.input.cur_span();
if !is_one_of!(self, Url, Function) {
return Err(Error::new(
span,
ErrorKind::Expected("url or function (with 'url' or 'src' name) token"),
));
}
match bump!(self) {
Token::Url { value, raw } => {
let name_length = raw.0.len() as u32;
let name = Ident {
span: Span::new(span.lo, span.lo + BytePos(name_length)),
value: self.input.atom("url"),
raw: Some(raw.0),
};
let value = Some(Box::new(UrlValue::Raw(UrlValueRaw {
span: Span::new(span.lo + BytePos(name_length + 1), span.hi - BytePos(1)),
value,
raw: Some(raw.1),
})));View on GitHub (pinned to 5176682b65)
Solutions
- Use url(...) or src(...) syntax with a valid URL argument
- Quote the URL if it contains special characters
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at crates/swc_css_parser/src/parser/values_and_units/mod.rs:2594 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/6869dad1bf6e322a.
Report an issue: GitHub.