Troubleshooting
This guide covers common issues you might encounter while developing BookWish and their solutions.
Database Issues
Can't Connect to PostgreSQL
Error: P1001: Can't reach database server at [host]
Causes & Solutions:
-
PostgreSQL not running
# Check if PostgreSQL is running
pg_isready
# Start PostgreSQL
# macOS with Homebrew:
brew services start postgresql@15
# Linux:
sudo systemctl start postgresql -
Wrong DATABASE_URL format
# Correct format:
DATABASE_URL=postgresql://[user]:[password]@[host]:[port]/[database]
# Example:
DATABASE_URL=postgresql://postgres:password@localhost:5432/bookwish -
Database doesn't exist
# Create database
createdb bookwish
# Or using psql:
psql postgres
CREATE DATABASE bookwish; -
Authentication failed
- Check username and password in
DATABASE_URL - For Supabase, use the correct password from your dashboard
- Verify user has permissions:
GRANT ALL PRIVILEGES ON DATABASE bookwish TO postgres;
- Check username and password in
-
Supabase connection issues
- Use "Direct connection" URL for migrations
- Use "Pooled connection" URL for application runtime
- Check IP allowlist in Supabase dashboard
- Verify project is not paused (free tier)
Migration Failures
Error: Migration failed to apply cleanly to the shadow database
Solutions:
cd backend
# Reset database (development only - deletes all data!)
npx prisma migrate reset
# Or force migrate
npx prisma migrate deploy
# Regenerate Prisma client
npm run prisma:generate
Error: The table 'users' already exists
This happens if migrations are out of sync. Solutions:
# Mark migrations as applied without running them
npx prisma migrate resolve --applied [migration-name]
# Or reset and re-run
npx prisma migrate reset
Prisma Client Out of Sync
Error: Prisma Client not initialized or Unknown field 'fieldName'
Solution:
cd backend
# Regenerate Prisma Client
npm run prisma:generate
# Restart development server
npm run dev
Database Connection Pool Exhausted
Error: Error: Can't reach database server. Connection pool exhausted.
Solutions:
-
Check for unclosed connections
- Ensure you're not creating new PrismaClient instances
- Use singleton pattern (already configured in the codebase)
-
Increase connection pool size (if using Supabase)
- Upgrade to paid tier for more connections
- Use connection pooling (PgBouncer)
-
Restart backend
# Kill backend process
pkill -f "ts-node"
# Restart
npm run dev
Redis Issues
Can't Connect to Redis
Error: Error: connect ECONNREFUSED 127.0.0.1:6379
Solutions:
-
Redis not running
# Check if Redis is running
redis-cli ping
# Start Redis
# macOS with Homebrew:
brew services start redis
# Linux:
sudo systemctl start redis
# Or run in foreground:
redis-server -
Wrong REDIS_URL
# Local Redis
REDIS_URL=redis://localhost:6379
# Remote Redis (Railway, Upstash)
REDIS_URL=redis://default:password@host:port -
Redis port conflict
# Check what's using port 6379
lsof -i:6379
# Or use different port
redis-server --port 6380
REDIS_URL=redis://localhost:6380
Redis Connection Timeout
Error: Redis connection timeout
Solutions:
- Check firewall settings
- Increase timeout in Redis client configuration
- Use local Redis for development instead of remote
Clear Redis Cache
If you're seeing stale data:
# Clear all Redis data
redis-cli FLUSHALL
# Or connect and flush
redis-cli
> FLUSHALL
> exit
Flutter Build Issues
Build Runner Conflicts
Error: Conflicting outputs were detected and the build is unable to prompt for permission to remove them
Solution:
cd app
# Use delete-conflicting-outputs flag
flutter pub run build_runner build --delete-conflicting-outputs
# Or clean first
flutter clean
flutter pub get
flutter pub run build_runner build --delete-conflicting-outputs
Build Runner Generation Failures
Error: [SEVERE] Failed to build
Common causes:
-
Syntax error in annotated file
- Check the file mentioned in error
- Fix Dart syntax errors
- Ensure
@riverpodannotations are correct
-
Missing dependencies
flutter pub get -
Outdated generated files
# Delete all generated files
find . -name "*.g.dart" -delete
# Regenerate
flutter pub run build_runner build --delete-conflicting-outputs
iOS Build Errors
Error: CocoaPods not installed or pod install failed
Solutions:
-
Install CocoaPods
sudo gem install cocoapods -
Update pods
cd app/ios
rm -rf Pods Podfile.lock
pod install --repo-update
cd ../.. -
Clean and rebuild
flutter clean
cd app/ios
pod install
cd ../..
flutter run
Error: No signing certificate "iOS Development" found
Solutions:
- Open
app/ios/Runner.xcworkspacein Xcode - Select Runner > Signing & Capabilities
- Choose your development team
- Enable "Automatically manage signing"
Error: Module 'firebase_core' not found
Solution:
cd app/ios
rm -rf Pods Podfile.lock .symlinks
pod install
cd ../..
flutter clean
flutter pub get
flutter run
Android Build Errors
Error: SDK location not found
Solutions:
-
Set ANDROID_HOME
# macOS/Linux (add to ~/.zshrc or ~/.bashrc)
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
# Or create local.properties
echo "sdk.dir=$HOME/Library/Android/sdk" > app/android/local.properties -
Accept Android licenses
flutter doctor --android-licenses
Error: Gradle build failed
Solutions:
-
Clean Gradle cache
cd app/android
./gradlew clean
cd ../..
flutter clean
flutter pub get -
Update Gradle wrapper
cd app/android
./gradlew wrapper --gradle-version=8.0
cd ../.. -
Check Java version
java -version
# Should be Java 11 or higher
Error: Execution failed for task ':app:processDebugGoogleServices'
Solutions:
- Verify
google-services.jsonis inapp/android/app/ - Ensure it's valid JSON (download fresh from Firebase Console)
- Check that package name matches your app
Flutter Doctor Issues
Warning: Android toolchain - develop for Android devices
Solutions:
# Install Android SDK
flutter doctor --android-licenses
# Or install Android Studio
# Download from: https://developer.android.com/studio
Warning: Xcode - develop for iOS and macOS
Solutions (macOS only):
# Install Xcode from App Store
# Then run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
sudo xcodebuild -license accept
Backend Build Issues
TypeScript Compilation Errors
Error: TSError: ⨯ Unable to compile TypeScript
Solutions:
-
Check for syntax errors
npm run lint -
Clear node_modules
rm -rf node_modules package-lock.json
npm install -
Update TypeScript
npm install typescript@latest
Missing Dependencies
Error: Cannot find module 'moduleName'
Solutions:
# Install missing dependency
npm install moduleName
# Or reinstall all dependencies
rm -rf node_modules package-lock.json
npm ci
Port Already in Use
Error: Error: listen EADDRINUSE: address already in use :::3000
Solutions:
-
Kill process on port 3000
# Find process
lsof -ti:3000
# Kill it
kill -9 $(lsof -ti:3000)
# Or on Windows:
netstat -ano | findstr :3000
taskkill /PID [PID] /F -
Use different port
PORT=3001 npm run dev
Environment Variable Validation Errors
Error: Environment validation failed: JWT_SECRET: String must contain at least 32 character(s)
Solution:
- Open
backend/.env - Generate secure secrets:
# Generate JWT_SECRET
openssl rand -hex 32
# Generate JWT_REFRESH_SECRET
openssl rand -hex 32
# Add to .env file
JWT_SECRET=generated_secret_here
JWT_REFRESH_SECRET=another_generated_secret_here
API Integration Issues
Firebase Push Notifications Not Working
Symptoms:
- Push notifications not sending
firebase.not_initializedin logs
Solutions:
-
Check environment variables
# Required in backend/.env:
FIREBASE_PROJECT_ID=your-project-id
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nYour key\n-----END PRIVATE KEY-----\n"
FIREBASE_CLIENT_EMAIL=firebase-adminsdk-xxxxx@your-project.iam.gserviceaccount.com -
Private key format
- In
.env, use literal\n(two characters) - Code will replace
\\nwith actual newlines - Don't escape the newlines in environment variables
- In
-
Generate new credentials
- Firebase Console > Project Settings > Service Accounts
- Click "Generate new private key"
- Copy values to
.env
Stripe Webhook Failures
Error: Webhook signature verification failed
Solutions:
-
Use Stripe CLI for local testing
# Install Stripe CLI
brew install stripe/stripe-cli/stripe
# Login
stripe login
# Forward webhooks to local backend
stripe listen --forward-to localhost:3000/v1/webhooks/stripe
# Copy webhook signing secret to .env
STRIPE_WEBHOOK_SECRET=whsec_... -
Verify webhook secret
- Check Stripe Dashboard > Developers > Webhooks
- Copy signing secret to
STRIPE_WEBHOOK_SECRET
Square OAuth Errors
Error: Encryption key required for Square OAuth
Solution:
# Generate encryption key
openssl rand -base64 32
# Add to backend/.env
ENCRYPTION_KEY=generated_key_here
Network & Connectivity Issues
Flutter App Can't Connect to Backend
Symptoms:
- API calls failing with connection errors
- Timeouts or "unable to connect"
Solutions:
-
Check backend is running
curl http://localhost:3000/health -
iOS Simulator: Use localhost
// In app configuration
baseUrl: 'http://localhost:3000' -
Android Emulator: Use 10.0.2.2
// In app configuration
baseUrl: 'http://10.0.2.2:3000' -
Physical Device: Use computer's IP
# Find your IP
ifconfig | grep "inet "
# Use in app (example)
baseUrl: 'http://192.168.1.100:3000' -
Check firewall settings
- Allow incoming connections on port 3000
- Disable VPN if causing issues
CORS Errors (Web)
Error: Access to fetch at 'http://localhost:3000' from origin 'http://localhost:3001' has been blocked by CORS
Solutions:
-
Backend already has CORS configured
- Check
backend/src/index.tsfor CORS middleware - Should allow localhost origins in development
- Check
-
Verify origin is allowed
// In backend/src/index.ts
app.use(cors({
origin: ['http://localhost:3001', 'http://localhost:3002'],
credentials: true
}));
Performance Issues
Slow Backend Startup
Symptoms:
- Backend takes a long time to start
- Database connection timeouts
Solutions:
-
Check PostgreSQL is responsive
psql $DATABASE_URL -c "SELECT 1" -
Use local Redis
- Remote Redis can be slow
- Use
redis://localhost:6379for development
-
Check for large migrations
- Large seed data can slow startup
- Comment out seed in
prisma:migratescript during development
Slow Flutter Build Times
Solutions:
-
Stop
build_runner watch- Only run when needed
- Use manual builds for faster iteration
-
Clean build cache periodically
flutter clean -
Use physical device instead of simulator
- Physical devices often run faster
- Less overhead than emulator
-
Optimize code generation
- Only annotate what needs to be generated
- Remove unused generated files
Development Environment Issues
VS Code Flutter Extension Issues
Symptoms:
- Code completion not working
- Flutter commands not available
Solutions:
-
Reload VS Code
- Command Palette > Developer: Reload Window
-
Verify Flutter SDK path
- Command Palette > Flutter: Change SDK
- Point to your Flutter installation
-
Reinstall extensions
- Uninstall Flutter and Dart extensions
- Restart VS Code
- Reinstall extensions
Git Issues
Error: Your branch is behind 'origin/main'
Solution:
git pull origin main
Error: Merge conflict in [file]
Solution:
# View conflicts
git status
# Edit files to resolve conflicts
# Then:
git add .
git commit -m "Resolve merge conflicts"
Getting Help
If you're still experiencing issues:
-
Check GitHub Issues
- Search existing issues
- Create new issue with full error details
-
Check Logs
- Backend: Terminal output from
npm run dev - Flutter: Terminal output from
flutter run - Database:
npx prisma studiofor data inspection
- Backend: Terminal output from
-
Use Debug Mode
# Backend with verbose logging
DEBUG=* npm run dev
# Flutter with verbose output
flutter run -v -
Provide Error Context When asking for help, include:
- Full error message
- Commands that caused the error
- Operating system and versions
- Relevant configuration (without secrets!)
Prevention Tips
-
Keep dependencies updated
# Backend
cd backend && npm outdated
# Flutter
cd app && flutter pub outdated -
Use version control
- Commit working state frequently
- Create branches for experiments
- Use
.gitignorefor build artifacts
-
Regular maintenance
# Clean Flutter build cache weekly
flutter clean
# Clear Redis cache when switching branches
redis-cli FLUSHALL
# Reset database when schema changes
npx prisma migrate reset -
Monitor logs
- Watch for warnings
- Address deprecations early
- Keep error tracking enabled
Next Steps
- Review Architecture to understand the system
- Check Contributing Guidelines before making changes
- Explore API Documentation for endpoint details