# API Production Build Fix - Quick Summary

## Problem
```bash
ls: cannot access 'apps/api/dist/server.js': No such file or directory
```

## Root Cause
Server was using old build command `tsc + tsc-alias`, but codebase switched to `tsup` bundler.

## Solution

### 1. Fixed Build Config
Changed `tsup.config.ts` format from `cjs` → `esm` (required for top-level await)

### 2. Updated package.json
Added `prebuild` script for clarity

### 3. Created Deployment Tools
- `scripts/deploy-production.sh` - Automated deployment
- `docs/DEPLOYMENT_TROUBLESHOOTING.md` - Manual procedures

## Deploy Commands

### Quick Deploy
```bash
./scripts/deploy-production.sh
```

### Manual Deploy
```bash
ssh ubuntu@vps-4d8abcb7
sudo -u myroadtrip bash -lc '
  cd /srv/myroadtrip/repo
  git pull origin main
  pnpm install --frozen-lockfile
  rm -rf apps/api/dist
  pnpm --filter @my-roadtrip/api build
  ls -lh apps/api/dist/server.js
'
sudo systemctl restart myroadtrip-api
```

## Verification
```bash
# Check build output
ssh ubuntu@vps-4d8abcb7 "ls -lh /srv/myroadtrip/repo/apps/api/dist/server.js"

# Health check
curl https://api.roadtripper.io/health
```

## Files Changed
- `apps/api/tsup.config.ts` - Changed format to ESM
- `apps/api/package.json` - Added prebuild script
- `scripts/deploy-production.sh` - New deployment script (chmod +x)
- `docs/DEPLOYMENT_TROUBLESHOOTING.md` - Troubleshooting guide
- `API_BUILD_FIX.md` - Detailed explanation

## Status
✅ Local build tested (594KB server.js generated)
✅ ESM format working with top-level await
⏳ Ready for production deployment
