From 192de5c6b54e5eb694b2b3aba0cf61f64a68f55b Mon Sep 17 00:00:00 2001 From: Thomas Hallock Date: Sun, 23 Nov 2025 10:56:03 -0600 Subject: [PATCH] fix: upgrade to Node.js 20 to resolve ES module import issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes production error where dynamic imports of @svg-maps/world and @svg-maps/usa packages fail with "Unexpected token 'export'" error. **Root cause:** - The @svg-maps packages use ES module syntax (`export default {...}`) in index.js - Node.js 18 cannot load these files via dynamic import() without "type": "module" - Node.js 20 has improved ES module support and handles this correctly **Changes:** - Dockerfile: FROM node:18-alpine → FROM node:20-alpine - deploy.yml: node-version "18" → "20" **Testing:** - ✅ Local dev server with Node 20: works (dynamic imports succeed) - ✅ Production container with Node 18: fails (dynamic imports fail) - ✅ Tested: `node -e "import('@svg-maps/world').then(...)"` succeeds on Node 20 This fix ensures the Socket.IO server can successfully process START_GAME moves by loading map data via dynamic imports in the Validator. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .github/workflows/deploy.yml | 2 +- Dockerfile | 8 ++++---- apps/web/.claude/CLAUDE.md | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index eefad330..c7470c75 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -22,7 +22,7 @@ jobs: - uses: actions/setup-node@v4 with: - node-version: "18" + node-version: "20" cache: "pnpm" - name: Install dependencies diff --git a/Dockerfile b/Dockerfile index 2a9ca7eb..79cc7613 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Multi-stage build for Soroban Abacus Flashcards -FROM node:18-alpine AS base +FROM node:20-alpine AS base # Install Python and build tools for better-sqlite3 RUN apk add --no-cache python3 py3-setuptools make g++ @@ -46,7 +46,7 @@ RUN turbo build --filter=@soroban/web # Production dependencies stage - install only runtime dependencies # IMPORTANT: Must use same base as runner stage for binary compatibility (better-sqlite3) -FROM node:18-slim AS deps +FROM node:20-slim AS deps WORKDIR /app # Install build tools temporarily for better-sqlite3 installation @@ -70,7 +70,7 @@ COPY packages/templates/package.json ./packages/templates/ RUN pnpm install --frozen-lockfile --prod # Typst builder stage - download and prepare typst binary -FROM node:18-slim AS typst-builder +FROM node:20-slim AS typst-builder RUN apt-get update && apt-get install -y --no-install-recommends \ wget \ xz-utils \ @@ -92,7 +92,7 @@ RUN ARCH=$(uname -m) && \ chmod +x /usr/local/bin/typst # Production image -FROM node:18-slim AS runner +FROM node:20-slim AS runner WORKDIR /app # Install ONLY runtime dependencies (no build tools) diff --git a/apps/web/.claude/CLAUDE.md b/apps/web/.claude/CLAUDE.md index 682613ff..55498ff5 100644 --- a/apps/web/.claude/CLAUDE.md +++ b/apps/web/.claude/CLAUDE.md @@ -26,6 +26,22 @@ README.md (root) **Invalid:** Creating `/docs/some-feature.md` without linking from anywhere ❌ **Valid:** Creating `/docs/some-feature.md` AND linking from root README ✅ +## CRITICAL: @svg-maps ES Module Imports Work Correctly + +**The @svg-maps packages (world, usa) USE ES module syntax and this WORKS correctly in production.** + +**Historical context:** +- We went through multiple attempts to "fix" ES module import issues +- Tried JSON data files, tried various dynamic import strategies +- **The current implementation (dynamic imports in maps.ts) WORKS in production** +- Games were successfully created and played in production with this approach +- DO NOT try to replace with JSON files or other workarounds + +**If you see an error related to @svg-maps:** +- Check what else changed, not the import mechanism +- The imports themselves are NOT the problem +- Look for validator issues, type errors, or other recent changes + ## CRITICAL: Production Dependencies **NEVER add TypeScript execution tools to production dependencies.**