๐ง Troubleshooting Guide
Debug Like a Pro: Common issues, solutions, and debugging techniques for Uptime Watcher development.
๐จ Common Issues & Solutionsโ
Development Environmentโ
1. SQLite WASM Not Foundโ
Error: Error: Cannot find module 'node-sqlite3-wasm.wasm'
Solution:
# Copy WASM file to dist-electron
npm run postbuild
# Or manually copy
npm run copy-wasm
Prevention: The postinstall
script should handle this automatically, but sometimes fails in certain environments.
2. Port 5173 Already in Useโ
Error: Port 5173 is already in use
Solutions:
# Kill the process using the port
npx kill-port 5173
# Or use a different port
npm run dev -- --port 5174
3. Electron Won't Startโ
Error: Electron starts but shows blank screen
Solutions:
- Check Vite dev server: Ensure
npm run dev
is running on port 5173 - Clear cache: Delete
.vite
anddist-electron
directories - Rebuild:
npm run clean && npm install && npm run postbuild
4. Hot Reload Not Workingโ
Solutions:
- Restart dev server: Stop and restart
npm run electron-dev
- Check file watchers: Ensure file system watchers aren't exceeded
- Reload manually: Use Ctrl+R in Electron window
Database Issuesโ
1. Database Locked Errorโ
Error: database is locked
Solutions:
# Check for hanging connections
npm run electron-dev -- --debug
# Look for unclosed database connections in logs
# Force restart
pkill -f electron
npm run electron-dev
Prevention: Always use repository pattern and transactions
2. Migration Errorsโ
Error: Schema/migration related errors
Solutions:
- Backup data: Export data if needed
- Delete database: Remove SQLite files in user data directory
- Restart: Application will recreate with latest schema
Database Locations:
- Windows:
%APPDATA%/uptime-watcher/
- macOS:
~/Library/Application Support/uptime-watcher/
- Linux:
~/.config/uptime-watcher/
3. Transaction Errorsโ
Error: cannot start a transaction within a transaction
Solution: Use internal repository methods within existing transactions:
// โ Wrong - creates nested transaction
await databaseService.executeTransaction(async () => {
await repository.create(data); // This creates another transaction
});
// โ
Correct - use internal method
await databaseService.executeTransaction(async (db) => {
repository.createInternal(db, data); // Works within transaction
});
TypeScript Issuesโ
1. Type Errors in IPCโ
Error: TypeScript errors on window.electronAPI
Solutions:
- Check preload types: Ensure types are properly exposed
- Restart TypeScript: Reload VS Code or restart TypeScript service
- Check imports: Verify type imports in components
2. Module Resolution Errorsโ
Error: Cannot resolve module paths
Solutions:
- Check tsconfig.json: Verify path mappings
- Restart TypeScript: Reload language service
- Check imports: Use correct relative/absolute paths
Build & Packaging Issuesโ
1. Build Failsโ
Error: Various build-time errors
Solutions:
# Clean and rebuild
npm run clean
npm install
npm run build
# Check TypeScript
npm run check-types
# Check linting
npm run lint
2. Missing Dependencies in Productionโ
Error: Module not found in packaged app
Solutions:
- Check package.json: Ensure dependencies (not devDependencies)
- Test build locally:
npm run dist
and test the built app - Check bundling: Verify Vite/Electron builder configuration
3. WASM File Missing in Packageโ
Error: SQLite WASM not found in packaged app
Solution: Ensure postbuild
script runs:
// package.json
{
"scripts": {
"build": "... && npm run postbuild",
"postbuild": "npx cpy node_modules/node-sqlite3-wasm/dist/node-sqlite3-wasm.wasm dist-electron/ --flat"
}
}
Runtime Issuesโ
1. Memory Leaksโ
Symptoms: App becomes slow over time, high memory usage
Solutions:
- Check event listeners: Ensure proper cleanup
- Monitor stores: Look for state that grows infinitely
- Database connections: Verify proper connection management
Debugging:
// Monitor memory in development
console.log(process.memoryUsage());
// Check event listener count
console.log(eventBus.listenerCount());
2. Performance Issuesโ
Symptoms: Slow UI, delayed responses
Solutions:
- Profile React: Use React DevTools Profiler
- Check database queries: Monitor query performance
- Optimize stores: Use selectors to prevent unnecessary re-renders
3. Notification Issuesโ
Error: Desktop notifications don't work
Solutions:
- Check permissions: Verify notification permissions
- Platform differences: Test on target platforms
- Service worker: Ensure notification service is running
๐ Debugging Techniquesโ
Loggingโ
Enable Debug Loggingโ
# Maximum debugging
npm run electron-dev -- --debug
# Production-level logging
npm run electron-dev -- --log-production
# Info-level logging
npm run electron-dev -- --log-info
Backend Loggingโ
import { logger } from "./utils/logger";
// Use structured logging
logger.debug("Operation started", { operationId, userId });
logger.info("Site created", { siteId: site.id, name: site.name });
logger.error("Database error", { error: error.message, query });
Frontend Loggingโ
// Use console methods with context
console.log("[SitesStore] Adding site:", site);
console.error("[API] Failed to create site:", error);
// Use store action logging (built-in)
logStoreAction("SitesStore", "addSite", { site });
DevToolsโ
React DevToolsโ
- Installation: Automatically available in development
- Usage: Inspect component state, props, and performance
- Profiler: Profile component render performance
Electron DevToolsโ
- Access: F12 in the application window
- Console: Check for JavaScript errors and logs
- Network: Monitor network requests (though limited in Electron)
- Sources: Debug TypeScript/JavaScript code
VS Code Debuggingโ
Configuration available in .vscode/launch.json
:
{
"name": "Debug Electron Main",
"program": "${workspaceFolder}/dist-electron/main.js",
"request": "launch",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
"type": "node"
}
Monitoringโ
Database Operationsโ
// Monitor transaction performance
const startTime = Date.now();
await databaseService.executeTransaction(async (db) => {
// ... operations
});
logger.debug("Transaction completed", {
duration: Date.now() - startTime,
});
Event Busโ
// Monitor event flow
eventBus.use(async (eventName, data, correlationId, next) => {
logger.debug(`[Event] ${eventName}`, { correlationId });
const start = Date.now();
await next();
logger.debug(`[Event] ${eventName} completed`, {
correlationId,
duration: Date.now() - start,
});
});
IPC Communicationโ
// Log IPC calls in development
if (isDev) {
ipcMain.on("*", (event, ...args) => {
console.log("[IPC]", event.channel, args);
});
}
๐ ๏ธ Development Toolsโ
VS Code Extensionsโ
Recommended extensions for optimal development:
{
"recommendations": [
"ms-vscode.vscode-typescript-next",
"bradlc.vscode-tailwindcss",
"ms-vscode.vscode-eslint",
"esbenp.prettier-vscode",
"ms-vscode.vscode-jest",
"ms-playwright.playwright"
]
}
Package Scripts for Debuggingโ
# Debug specific areas
npm run debug:electron # Debug Electron main process
npm run debug:renderer # Debug renderer with source maps
npm run lint:circular # Check for circular dependencies
npm run lint:complexity # Check code complexity
npm run lint:duplicates # Check for code duplication
Testing During Debuggingโ
# Run tests in watch mode
npm run test:watch
# Test specific files
npm test -- --testNamePattern="SitesStore"
# Backend tests only
npm run test:electron
# Frontend tests only
npm run test:frontend
๐ง Performance Optimizationโ
Database Performanceโ
- Use transactions for multiple operations
- Batch operations where possible
- Index frequently queried fields
- Monitor query performance with logging
Frontend Performanceโ
- Use React.memo for expensive components
- Optimize Zustand selectors to prevent unnecessary re-renders
- Debounce user input for search/filter operations
- Virtualize large lists if needed
Memory Managementโ
- Clean up event listeners in useEffect cleanup
- Dispose of subscriptions when components unmount
- Monitor store state growth to prevent memory leaks
- Use WeakMap/WeakSet for caching when appropriate
๐ Getting Helpโ
Internal Resourcesโ
- Documentation: Check
docs/
directory first - Code Examples: Look at existing implementations
- Tests: Check test files for usage examples
- Architecture: Review ADRs for design decisions
External Resourcesโ
- Electron Issues: Electron GitHub Issues
- React Issues: React GitHub Issues
- Vite Issues: Vite GitHub Issues
- TypeScript Issues: TypeScript GitHub Issues
Reporting Issuesโ
When reporting issues, include:
- Environment: OS, Node.js version, npm version
- Steps to reproduce: Exact steps to reproduce the issue
- Expected behavior: What should happen
- Actual behavior: What actually happens
- Logs: Relevant console/file logs
- Code: Minimal reproducible example
๐ก Pro Tip: When debugging, start with the logs and work backwards. Most issues leave a trail in the console or log files.