TLDR: sql.js loads SQLite into a WASM module with a single linear memory buffer. After indexing 18,000+ files that memory is large and fragmented. Reconstructing a Database() object on that same heap fails with "memory access out of bounds". The fix is a build-time esbuild plugin that injects a resetCache() function into the sql.js bundle, allowing the WASM module to be fully discarded and reloaded from scratch on rebuild.