swc-project/swc · error
cap == 0
Error message
cap == 0
What it means
CachingResolver::new asserts its cache capacity is non-zero before building the LruCache (which requires NonZeroUsize). This fires when a caller constructs a CachingResolver with cap == 0, i.e. a zero-sized cache, which the LRU implementation cannot represent; the default constructor uses 40.
Source
Thrown at crates/swc_ecma_loader/src/resolvers/lru.rs:35
}
impl<R> Default for CachingResolver<R>
where
R: Resolve + Default,
{
fn default() -> Self {
Self::new(40, Default::default())
}
}
impl<R> CachingResolver<R>
where
R: Resolve,
{
pub fn new(cap: usize, inner: R) -> Self {
Self {
cache: Mutex::new(LruCache::new(
NonZeroUsize::try_from(cap).expect("cap == 0"),
)),
inner,
}
}
}
impl<R> Resolve for CachingResolver<R>
where
R: Resolve,
{
fn resolve(&self, base: &FileName, src: &str) -> Result<Resolution, Error> {
{
let mut lock = self.cache.lock();
//
if let Some(v) = lock.get(&(base.clone(), src.to_string())) {
return Ok(v.clone());
}
}View on GitHub (pinned to 5176682b65)
Solutions
- Pass a capacity of at least 1 to CachingResolver::new
- Use CachingResolver::default() when no specific capacity is needed (defaults to 40)
- If zero caching is desired, use the inner resolver directly instead of the caching wrapper
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/swc_ecma_loader/src/resolvers/lru.rs:35 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/3f5eec0822c26f27.
Report an issue: GitHub.