Skip to content

Conversation

@RobHannay
Copy link

@RobHannay RobHannay commented Jan 16, 2026

Summary

  • Add clear_cache_without_tsconfig() method that clears path cache while preserving tsconfig cache
  • Useful for HMR scenarios where tsconfig.json doesn't change during development

Problem

When using tsconfig path aliases (especially wildcard patterns like "*": ["./src/*"]), HMR intermittently fails with "Module not found" errors. This happens because:

  1. During HMR, rspack calls clear_cache() which clears both the path cache AND tsconfig cache
  2. Re-parsing tsconfig.json on every HMR update is wasteful
  3. Race conditions during re-parsing can cause intermittent module resolution failures

Related issue: web-infra-dev/rspack#12753

Solution

Add two new methods:

  • Cache::clear_without_tsconfig() - clears only the path cache
  • ResolverGeneric::clear_cache_without_tsconfig() - public API that clears path cache but preserves tsconfig cache

This allows rspack to preserve tsconfig state during HMR while still invalidating file system caches.

Test plan

  • All existing tests pass (114 unit tests + 9 integration tests)
  • Build compiles successfully

Next steps

Once this PR is merged, a second PR is needed in rspack to use the new method during HMR:

  • Update crates/rspack_core/src/compiler/rebuild.rs:58 to call clear_cache_without_tsconfig() instead of clear_cache()

🤖 Generated with Claude Code

Add a new method `clear_cache_without_tsconfig()` that clears the path
cache while preserving the tsconfig cache. This is useful for HMR (Hot
Module Replacement) scenarios where tsconfig.json doesn't change during
development.

When using tsconfig path aliases (especially wildcard patterns like
`"*": ["./src/*"]`), HMR can intermittently fail with "Module not found"
errors because:

1. During HMR, rspack calls `clear_cache()` which clears both the path
   cache AND tsconfig cache
2. Re-parsing `tsconfig.json` on every HMR update is wasteful
3. Race conditions during re-parsing can cause intermittent module
   resolution failures

Related: web-infra-dev/rspack#12753

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant