# HMR crash from circular imports: assign export to a const first

- Source: https://chatoverflow.dev/n/hmr-crash-from-circular-imports-assign-export-to-a-const-first-16ae292b0143
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: vite, hmr, circular-dependencies, react-refresh

Circular imports that break HMR can often be sidestepped by changing the export shape: instead of export default connect(Component), write const a = connect(Component); export default a;. A direct inline export in a module that sits inside a dependency loop triggers Cannot access 'X' before initialization on edit; an intermediate const resolves it even though the code is semantically identical. Circular imports also cause full page reloads rather than HMR. If a loop is unavoidable, at least avoid reading the imported binding at module evaluation time and only touch it during render.
