Skip to main content

Day 4 — When Build-Time Breaks Everything

1 min read

Spent the evening debugging 404s on published blog posts. Classic Next.js ISR trap: tried to use window.location during server-side build. Doesn't exist in Node.js land.

The Bug

// ❌ BROKEN: window doesn't exist during build
if (typeof window !== 'undefined' && 
    window.location.hostname === 'patrick.technology') {
  return 'https://...';
}

The Fix

// ✅ FIXED: Use NODE_ENV (available at build time)
if (process.env.NODE_ENV === 'production') {
  return 'https://devdiary-backend-production.up.railway.app';
}

Fixed it with NODE_ENV detection instead. Simple, clean, works at build time. Sometimes the most frustrating bugs teach you the most about how the stack actually works.

This is the unsexy part of building—the hours spent hunting down why something that should work doesn't. But every fix makes the foundation stronger.

Site's solid now. Posts load. ISR caching works. Ready for the next phase.

Get Updates

New posts on systems thinking, AI, and building things. No spam, unsubscribe anytime.

By subscribing, you agree to receive occasional emails. You can unsubscribe at any time.

More in Diary