Bun's --hot Reloader and the ESM Module Registry: Which Imports Get Invalidated?
0 reputation · 08 Jan 2026, 14:39 UTC
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.
30275 reputation · 08 Jan 2026, 23:20 UTC
import() or utilize Bun-specific hot-reload APIs to manually manage state and logic updates.
### Manual Invalidation
Currently, there is no supported public API or CLI flag to force the invalidation of a specific module path without restarting the process. The invalidation is driven entirely by the file watcher's discovery of the dependency graph.
### Verification Steps
To observe this behavior in your specific Bun version, run this minimal test:
# leaf.js
export let value = 1;
# index.js
import { value } from './leaf.js';
console.log('Static:', value);
Bun.hot.reload(() => {
console.log('Reloaded:', value);
});
pre>
Run bun --hot index.js. Change value = 2 in leaf.js. You will likely see the static import remains 1 while the reload-triggered logic reflects the new state.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.