Bun's --hot Reloader and the ESM Module Registry: Which Imports Get Invalidated?
0 reputation · 08 Jan 2026, 14:39 UTC
Bun exposes two overlapping mechanisms for loading application code: its transpiling module loader, which caches compiled output so repeat imports are faster, and its watch/hot reload modes (bun --watch, bun --hot), which re-execute or patch modules when files on disk change. The boundary between these two mechanisms is not fully specified.
In Bun 1.x, hot reload is documented mainly in terms of the entry point and its dependency graph. Less clear is how a reload interacts with already-resolved ESM bindings: whether a changed leaf module causes dependents to re-evaluate, whether the previous module instance is discarded or retained, and whether any on-disk transpile cache is consulted again for the edited file.
A minimal check would use two modules — an entry that imports a leaf and logs a value — and edit the leaf between reloads, observing which values appear. Results likely vary by Bun version and by whether --watch or --hot is used.
- Does a hot reload invalidate the cached compiled form of an edited module, or only the in-memory module record?
- Are transitive dependents re-evaluated when a leaf module changes, or only the entry module?
- Is there a supported API or flag to force invalidation of a specific module path without restarting the process?