Common Issues and Fixes
Solutions to frequently encountered problems during development and deployment.
Build Failures
Postgres Package Bundled into Client Build
Error:
error during build:
node_modules/postgres/src/connection.js (5:9): "performance" is not exported by "__vite-browser-external"
Symptoms:
- Build fails during
vite build - Warnings about Node.js modules (
os,fs,net,tls,crypto) being externalized
Root Cause: Server-only code (database queries) is being pulled into the client bundle through import chains.
Solutions:
-
Move shared types to separate files without database imports:
// BAD: imports from file with drizzle-orm
import type { Config } from '../db/schema/config'
// GOOD: separate types file
import type { Config } from './types/config' -
Use dynamic imports for server-only services:
// BAD: Static import
import { ConfigService } from '../config'
// GOOD: Dynamic import
let ConfigService: typeof import('../config').ConfigService | null = null
async function getConfigService() {
if (!ConfigService) {
const module = await import('../config')
ConfigService = module.ConfigService
}
return ConfigService
} -
Configure Vite externals (
vite.config.ts):export default defineConfig({
optimizeDeps: {
exclude: ['postgres', 'drizzle-orm'],
},
ssr: {
external: ['postgres'],
},
})
Prevention:
- Keep database imports strictly in
routes/api/, services, and server-only files - Use
import typefor type-only imports - Consider file naming like
*.server.tsfor server-only code
Runtime Errors
TypeError: Cannot read properties of undefined
Context: Loading data in components
Error:
TypeError: Cannot read properties of undefined (reading 'length')
Root Cause: API response structure mismatch. Component accessing wrong property path.
Fix:
// BAD
const data = await response.json()
setSearchResults(data.items)
// GOOD
const data = await response.json()
setSearchResults(data.data?.items ?? [])
Prevention:
- Use optional chaining (
?.) and nullish coalescing (??) - Check API response structure
- Consider typed API client functions
Database Issues
Connection Refused
Error:
Error: connect ECONNREFUSED 127.0.0.1:5432
Solutions:
-
Verify PostgreSQL is running:
# Check status
pg_isready -h localhost -p 5432
# Start PostgreSQL (varies by OS)
# macOS:
brew services start postgresql
# Linux:
sudo systemctl start postgresql
# Windows:
net start postgresql-x64-18 -
Check DATABASE_URL:
echo $DATABASE_URL
# Should be: postgresql://user:pass@localhost:5432/cascadia -
Verify database exists:
psql -U postgres -c "\l"
Migration Errors
Error:
relation "items" does not exist
Solution:
# Push schema to database
npm run db:push
# Or run migrations
npm run db:generate
npm run db:migrate
Authentication Issues
Session Not Persisting
Symptoms:
- User logged out on page refresh
- API returns 401 after login
Solutions:
-
Check SESSION_SECRET:
# Must be at least 32 characters
SESSION_SECRET=your-random-32-character-secret-here -
Verify cookie settings:
- In development:
secure: false - In production:
secure: truewith HTTPS
- In development:
-
Check BASE_URL:
BASE_URL=http://localhost:3000 # Development
BASE_URL=https://your-domain.com # Production
OAuth Redirect Error
Error:
redirect_uri_mismatch
Solution: Ensure the redirect URI in your OAuth app matches:
http://localhost:3000/api/auth/oauth/{provider}/callback # Development
https://your-domain.com/api/auth/oauth/{provider}/callback # Production
File Upload Issues
Upload Fails with Large Files
Error:
PayloadTooLargeError: request entity too large
Solutions:
-
Check MAX_FILE_SIZE setting:
MAX_FILE_SIZE=500MB -
Configure Nginx (if using):
client_max_body_size 500M; -
Configure load balancer limits (cloud providers)
Files Not Saving
Solutions:
-
Check VAULT_ROOT exists and is writable:
ls -la $VAULT_ROOT -
Verify storage type configuration:
VAULT_TYPE=local
VAULT_ROOT=/app/vault
Docker Issues
Container Won't Start
Check logs:
docker-compose logs cascadia-app
Common causes:
-
Database not ready: Add healthcheck and depends_on in docker-compose.yml
-
Missing environment variables:
docker-compose config # Verify configuration -
Port conflict:
lsof -i :3000 # Check what's using the port
Out of Disk Space
Clean up Docker:
docker system prune -a
docker volume prune
Performance Issues
Slow Database Queries
Diagnose:
# Enable query logging
LOG_LEVEL=debug npm run dev
Solutions:
- Add database indexes for frequently queried columns
- Use pagination for large result sets
- Check for N+1 queries in relationships
High Memory Usage
Solutions:
-
Reduce Node.js heap size:
NODE_OPTIONS="--max-old-space-size=512" -
Enable streaming for large files
-
Implement pagination for large lists
Development Environment
Port Already in Use
Error:
Error: listen EADDRINUSE: address already in use :::3000
Solutions:
# Find process
lsof -i :3000 # macOS/Linux
netstat -ano | findstr :3000 # Windows
# Kill process
kill -9 <PID> # macOS/Linux
taskkill /PID <PID> /F # Windows
# Or use different port
PORT=3001 npm run dev
Node Modules Issues
Symptoms:
- Module not found errors
- Version conflicts
Solution:
rm -rf node_modules package-lock.json
npm install
Getting More Help
- Check the FAQ
- Search GitHub Issues
- Open a new issue with:
- Steps to reproduce
- Error messages
- Environment details (OS, Node version, etc.)