Technical Troubleshooting & FAQ
This document explains how to resolve common development, platform, and operational issues when working with scripture-habit.
1. Port Conflicts (8080, 9099, 5000)
- Symptom:
npm run dev:allornpm run emulatorsfails with:textPort 8080 is already in use by another process Port 9099 is already in use by another process - Cause: Previous Node.js or Firebase emulator processes did not terminate cleanly upon exit (common on Windows and macOS).
- Solution: Release the reserved ports with
kill-port:bashThen re-launch the dev environment:npx kill-port 8080 9099 5000 5173bashnpm run dev:all
2. Firebase Emulator Java Prerequisite
- Symptom:
firebase emulators:startfails withJava runtime not foundor exits immediately. - Cause: Cloud Firestore and Cloud Functions emulators run as Java JAR applications and require Java SE Development Kit (JDK) 11 or higher.
- Solution:
- Verify Java version:bash
java -version - Install OpenJDK 17 or 21 (e.g., via
winget install Microsoft.OpenJDK.21,brew install openjdk@21, or Eclipse Temurin). - Ensure
JAVA_HOMEis exported in your shell environment.
- Verify Java version:
3. App Check & Local Authentication
- Symptom: Backend Express API routes reject local requests from Vite or Emulators with
403 Forbidden: Invalid App Check. - Cause: App Check relies on hardware attestation providers (Play Integrity, DeviceCheck) unavailable in standard web browsers or local emulators.
- Solution:
- Bypass in Development: Ensure
SKIP_APP_CHECK=trueis set in your.env.localor environment. TheverifyAppCheckmiddleware inmiddleware.tsautomatically skips verification. - Debug Token Verification: When testing App Check behavior locally, register a debug token in the Firebase Console and configure the client SDK:typescript
// firebase.ts initialization self.FIREBASE_APPCHECK_DEBUG_TOKEN = true;
- Bypass in Development: Ensure
4. PWA & Service Worker in Local Development
- Symptom: Changes to
sw.tsor push notification event handlers are not taking effect duringnpm run dev. - Cause: Vite PWA plugin disables the Service Worker by default in development mode to prevent stale asset caching during rapid Hot Module Replacement (HMR).
- Solution: Start Vite with the PWA development flag enabled:bashOr launch with:
npm run dev:pwabashcross-env VITE_ENABLE_SW_IN_DEV=true vite
5. Vercel Serverless Function Cold Starts & API Warmup
- Symptom: First API request after a period of inactivity experiences a 1.5–2.5 second latency spike.
- Cause: Vercel Serverless Functions spin down during idle periods. Re-initializing the Express container and Firebase Admin connection takes time.
- Mitigation: The application utilizes a lightweight pre-warming hook:typescriptThis fires an asynchronous, low-priority
import { useApiWarmupOnMount } from '../../utils/api-warmup'; // In NewNote, SignupForm, Dashboard: useApiWarmupOnMount();GET /api/healthrequest upon mounting high-intent modal workflows, ensuring the serverless instance is warm before the user submits data.
6. Unit Testing Firestore Security Rules
- Symptom: Unit tests fail or Firestore rules reject operations because the emulator database context does not match the authenticated state.
- Solution: Use
@firebase/rules-unit-testingto instantiate an authenticated test context:typescriptimport { initializeTestEnvironment } from '@firebase/rules-unit-testing'; import { readFileSync } from 'fs'; const testEnv = await initializeTestEnvironment({ projectId: 'scripture-habit-auth', firestore: { rules: readFileSync('firestore.rules', 'utf8') } }); // Create an authenticated Firestore context const aliceDb = testEnv.authenticatedContext('alice').firestore();