soroban-abacus-flashcards/apps
Thomas Hallock a88bd5844c fix(server): lazy-load game validators to avoid ES module errors
Problem:
- Production server failing at startup with "Cannot find name 'scaleX'" and ES module errors
- @svg-maps/world ES module being imported in CommonJS context
- server.js uses require() which can't handle ES modules

Root cause:
- validators.ts imported all validators at module load time
- know-your-world validator imports maps.ts
- maps.ts imports @svg-maps/world (ES module)
- When server.js requires validators.ts, it fails

Solution:
- Convert validators.ts to use lazy loading with dynamic imports
- Validators are now loaded on-demand when first requested
- Cached after first load for performance
- This avoids importing ES modules until actually needed

Changes:
- validators.ts: Replace static imports with lazy loaders
- validators.ts: Make getValidator() async, returns Promise<GameValidator>
- session-manager.ts: Add await to getValidator() calls
- socket-server.ts: Add await to getValidator() calls
- validation/index.ts: Remove re-exports of validator instances
- game-registry.ts: Remove validator comparison (can't sync compare async)

Impact:
- Server.js can now start without ES module errors
- Next.js build still works (handles ES modules natively)
- Small performance hit on first validator access (cached thereafter)
- Breaking change: getValidator() is now async

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 06:17:09 -06:00
..
web fix(server): lazy-load game validators to avoid ES module errors 2025-11-20 06:17:09 -06:00