Skip to main content
This covers problems that occur in Sonamu’s Hot Module Replacement (HMR) system and how to solve them.

HMR Not Working

Symptoms

The server doesn’t automatically restart when you modify files.

Causes

  1. HMR boundary not properly configured
  2. File watcher not detecting file changes
  3. HMR failure due to circular dependencies

Solutions

1. Restart Development Server

2. Check HMR Boundary

HMR boundary is configured in hmr-hook-register.ts:
Modify this file to change HMR boundaries.

3. Increase File Watcher Limit (Linux/macOS)

4. Check .gitignore Patterns

Performance issues can occur if HMR watches directories like node_modules or dist.

Error After File Change

Symptoms

HMR works when you modify files but errors occur:

Causes

  1. Circular dependency
  2. Dynamic import not properly handled
  3. ESM/CommonJS mixing

Solutions

1. Check Circular Dependencies

Remove discovered circular dependencies:

2. Check Dynamic Imports

Avoid dynamic imports within HMR boundaries:

Type Error After HMR

Symptoms

TypeScript type errors occur after HMR runs:

Cause

TypeScript server didn’t recognize HMR changes.

Solutions

1. Restart TypeScript Server

VSCode:

2. Restart Editor

3. Check tsconfig.json

HMR Performance Degradation

Symptoms

HMR is slow or server freezes every time you save a file.

Causes

  1. Too many files included in HMR boundary
  2. Heavy computations running at module loading time
  3. Memory leak

Solutions

1. Optimize HMR Boundary

Modify boundary pattern in hmr-hook-register.ts:

2. Optimize Module Initialization

Use lazy loading for heavy computations:

3. Memory Profiling

HMR Boundary Configuration Error

Symptoms

Cause

HMR boundary pattern is incorrect.

Solution

Use correct glob patterns in hmr-hook-register.ts:

HMR Not Working for Specific Files

Symptoms

HMR works fine for most files, but specific files don’t restart when changed.

Causes

  1. File doesn’t match HMR boundary pattern
  2. File is explicitly excluded
  3. File is cached by other modules

Solutions

1. Check If File Is Included in Boundary

Check logs when saving file:

2. Clear Cache

3. Check Filename Pattern

ESM/CommonJS Mixing Issues

Symptoms

Cause

HMR system tried to load ESM module as CommonJS.

Solutions

1. package.json Configuration

2. Specify File Extension

3. tsconfig.json Configuration