Troubleshoot Firebase emulator issues, rules violations, function errors, auth problems, and deployment failures. Guides systematic debugging using emulator UI, logs analysis, and Rules Playground.
/plugin marketplace add 2389-research/claude-plugins/plugin install firebase-development@2389-research-marketplaceThis skill inherits all available tools. When active, it can use any tool Claude has access to.
This sub-skill guides you through troubleshooting Firebase development issues systematically. It handles:
The workflow uses TodoWrite to track 8-10 steps from issue identification to verified fix.
Use this sub-skill when:
Do not use for:
This sub-skill integrates with superpowers:systematic-debugging for rigorous problem-solving:
Integration Pattern:
When to Escalate to Superpowers:
Do not escalate for:
All patterns are documented in the main @firebase-development skill. This sub-skill helps you diagnose and fix issues using those patterns.
Key Sections Referenced:
This sub-skill creates a TodoWrite checklist with 8-10 steps. Follow the checklist to systematically debug your Firebase issue.
Actions:
Analyze the error message, behavior, or symptom to categorize the issue:
Issue Categories:
Emulator Won't Start
Rules Violation
Function Error
Auth Issue
Deployment Failure
If unclear, use AskUserQuestion:
Question: "What type of issue are you experiencing?"
Header: "Issue Type"
Options:
- "Emulator Won't Start" (Port conflicts, initialization errors)
- "Rules Violation" (Permission denied, access errors)
- "Function Error" (500 errors, timeouts, not executing)
- "Auth Issue" (Login not working, token errors)
- "Deployment Failure" (Deploy command fails)
Document your classification before proceeding.
Actions:
For running emulators:
# Terminal output shows all emulator activity
# Look for:
# - Error messages in red
# - Warning messages in yellow
# - Function invocation logs
# - Rules evaluation results
# If emulators are running, watch terminal output
# as you reproduce the issue
For emulators that won't start:
# Check for port conflicts
lsof -i :4000 # Emulator UI
lsof -i :5001 # Functions
lsof -i :8080 # Firestore
lsof -i :9099 # Auth
lsof -i :5000 # Hosting (if configured)
# Kill conflicting process if found
kill -9 <PID>
# Check Firebase project configuration
cat firebase.json
cat .firebaserc
# Verify Node version matches functions runtime
node --version
# Should match functions/package.json engines.node (18 or 20)
For deployment errors:
# Check deployment log
cat firebase-debug.log
# Look for:
# - HTTP error codes (401, 403, 404)
# - Missing dependencies
# - Build failures
# - Permission errors
Document key error messages before proceeding to next step.
Actions:
# Emulator UI runs at http://127.0.0.1:4000
open http://127.0.0.1:4000
# Or manually navigate in browser
Emulator UI Features:
Firestore Tab
Authentication Tab
Functions Tab
Logs Tab
Use Emulator UI to:
Document findings (data present/missing, users exist/missing, function calls succeeded/failed).
Actions:
Only if Step 1 identified a rules violation.
# Access Rules Playground in Emulator UI
# Navigate to: Firestore ’ Rules Playground tab
Rules Playground Workflow:
Select Operation Type
Specify Document Path
users/user123 or teams/team1/posts/post456Set Auth Context
Add Request Data (for create/update)
Run Simulation
Common Rules Issues:
// Issue: Helper function not accessible
// Fix: Define function inside match block or at root level
// Issue: Admin SDK operations counted as client operations
// Fix: Admin SDK bypasses rules (only client SDK is validated)
// Issue: Rules not reloading
// Fix: Restart emulators (Ctrl+C, then firebase emulators:start)
Document which rule is failing and why (auth missing, field validation failed, etc.).
Actions:
Only if Step 1 identified a function error.
Add strategic logging:
// functions/src/handlers/myFunction.ts
export async function myFunction(req: Request, res: Response) {
console.log('=
myFunction called');
console.log('=å Request body:', JSON.stringify(req.body, null, 2));
console.log('= Auth header:', req.headers['x-api-key'] || 'none');
try {
// Your logic here
const result = await someOperation();
console.log(' Operation succeeded:', result);
res.json({ success: true, message: 'Success', data: result });
} catch (error) {
console.error('L Error in myFunction:', error);
console.error('Stack trace:', (error as Error).stack);
res.status(500).json({ success: false, message: 'Internal error' });
}
}
What to log:
Watch terminal output:
# Terminal shows all console.log output in real-time
# Reproduce the issue and watch logs appear
# Functions tab in Emulator UI also shows logs
# but terminal is more detailed
Common Function Errors:
app.use(cors({ origin: true }))Document where in function flow the error occurs (auth, validation, database operation, response).
Actions:
Only if Step 1 identified an auth issue.
Check environment variables:
# For functions (API key pattern)
cat functions/.env
# Should contain keys but NOT committed to git
# For hosting (Firebase Auth pattern)
cat hosting/.env.local
# Should contain:
NEXT_PUBLIC_USE_EMULATORS=true
# Verify .gitignore excludes .env files
grep ".env" .gitignore
Check emulator connection code:
// hosting/src/lib/firebase.ts or similar
import { initializeApp } from 'firebase/app';
import { getAuth, connectAuthEmulator } from 'firebase/auth';
import { getFirestore, connectFirestoreEmulator } from 'firebase/firestore';
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const db = getFirestore(app);
// Connect to emulators in development
if (process.env.NEXT_PUBLIC_USE_EMULATORS === 'true') {
console.log('=' Connecting to Firebase emulators...');
connectAuthEmulator(auth, 'http://127.0.0.1:9099', { disableWarnings: true });
connectFirestoreEmulator(db, '127.0.0.1', 8080);
console.log(' Connected to emulators');
}
Check API key middleware (if using custom API keys):
// functions/src/middleware/apiKeyGuard.ts
// Verify:
// 1. Middleware checks x-api-key header
// 2. Prefix matches project (e.g., 'ooo_' for oneonone)
// 3. Query uses collectionGroup for apiKeys subcollection
// 4. Checks active: true flag
Test auth in Emulator UI:
Common Auth Issues:
Document auth method (Firebase Auth vs API keys) and where configuration is failing.
Actions:
Only if Step 1 identified a deployment failure.
Review firebase-debug.log:
# Last deployment log with full error details
cat firebase-debug.log
# Look for:
# - HTTP 401/403: Permissions issue (run firebase login)
# - HTTP 404: Project doesn't exist (check .firebaserc)
# - Build failures: Check predeploy hooks
# - Function size limits: Bundle too large
Check firebase.json configuration:
cat firebase.json
# Common issues:
# 1. Wrong predeploy command (mistyped build script)
# 2. Missing site/target configuration
# 3. Invalid rewrites syntax
# 4. Functions region mismatch
Verify project configuration:
# Check project ID matches Firebase console
cat .firebaserc
# Verify targets are linked (if using targets)
firebase target:list
# Check logged in user has permissions
firebase projects:list
Common Deployment Errors:
firebase login againfirebase use <project-id>firebase target:apply commandsTest predeploy hooks locally:
# Run build scripts manually before deploying
cd hosting
npm run build
cd ../functions
npm run build
# If builds succeed locally, predeploy should work
Document deployment step that's failing (rules, functions, hosting) and error code.
Actions:
Before making fixes or restarting emulators, preserve current state:
# Graceful shutdown (exports data automatically)
# Press Ctrl+C in terminal running emulators
# Verify export location
ls -la .firebase/emulator-data/
# Should contain:
# - firestore_export/ (Firestore data)
# - auth_export/ (Auth users)
# - config.json (emulator configuration)
Manual export (if needed):
# Export to custom location
firebase emulators:export ./backup-data
# Import from custom location (when restarting)
firebase emulators:start --import=./backup-data
State preservation checklist:
.firebase/emulator-data/firestore_export/auth_export/Why this matters:
Document export location and what data was preserved.
Actions:
Based on issue type identified in Step 1:
For Emulator Issues:
# Kill port-conflicting process
kill -9 <PID>
# Update firebase.json ports if needed
# Restart emulators
firebase emulators:start --import=.firebase/emulator-data
For Rules Violations:
// firestore.rules
// Add missing helper function
function isAuthenticated() {
return request.auth != null;
}
// Fix rule logic
match /users/{userId} {
allow read: if isAuthenticated() && request.auth.uid == userId;
allow write: if false; // Server-write-only
}
For Function Errors:
// Fix identified issue (missing await, wrong validation, etc.)
// Remove debug logs or keep strategic ones
console.log(' Function executed successfully');
// Ensure error handling is present
try {
// operation
} catch (error) {
console.error('Error:', error);
res.status(500).json({ success: false, message: 'Error message' });
}
For Auth Issues:
# Add missing environment variable
echo "NEXT_PUBLIC_USE_EMULATORS=true" >> hosting/.env.local
# Or fix API key query logic
# Or add test API key in Emulator UI
For Deployment Issues:
# Re-login if credentials expired
firebase login
# Switch to correct project
firebase use <project-id>
# Fix predeploy hooks in firebase.json
# Deploy again
firebase deploy
Test the fix:
# Restart emulators if needed (rules, config changes)
firebase emulators:start --import=.firebase/emulator-data
# Reproduce original issue
# - Make same API call
# - Trigger same function
# - Attempt same write operation
# Verify fix in Emulator UI
# - Check Firestore data
# - Check function logs
# - Test in Rules Playground
# Confirm terminal shows success logs, not errors
Success criteria:
Document what was changed and how fix was verified.
Actions:
Create or update project documentation:
# docs/debugging-notes.md (or add to existing docs)
## [Date] - [Issue Type]: [Brief Description]
**Symptom:**
- What error or behavior occurred
- Exact error message
- When it happened (after what change)
**Root Cause:**
- What was actually wrong
- Why it caused the symptom
- What configuration/code was incorrect
**Solution:**
- What was changed to fix it
- Code changes made
- Configuration updates
**Prevention:**
- How to avoid this in the future
- What to check before similar changes
- Validation steps to add
**References:**
- Related documentation sections
- Similar issues encountered before
- External resources that helped
Example entry:
## 2025-01-14 - Rules Violation: API Keys Collection Access
**Symptom:**
- PERMISSION_DENIED error when calling createApiKey function
- Error: "Missing or insufficient permissions"
- Occurred after adding new function
**Root Cause:**
- Firestore rules denied write access to apiKeys subcollection
- New function tried to create apiKey document from admin SDK
- Admin SDK should bypass rules, but was using wrong initialization
**Solution:**
- Changed function to use admin.firestore() instead of getFirestore()
- Admin SDK now correctly bypasses rules
- Function creates apiKeys successfully
**Prevention:**
- Always use admin SDK in Cloud Functions
- Client SDK for client apps (respects rules)
- Test all write operations in functions after adding new collections
**References:**
- firebase-development skill: Security Model section
- oneonone/functions/src/lib/firebase.ts for correct admin SDK usage
Commit documentation if appropriate:
git add docs/debugging-notes.md
git commit -m "docs: add debugging notes for [issue]"
Document added, issue logged for future reference.
Reference these known issues from the main @firebase-development skill:
lsof -i :<port>, kill process or change port.firebase/emulator-data/app.use(cors({ origin: true })) for browser requests.env, hosting uses .env.localNEXT_PUBLIC_USE_EMULATORS=true in hosting/.env.localThis sub-skill references patterns from the main firebase-development skill:
When debugging, always consult the main skill's Common Gotchas section first.
A debug session is complete when:
Invoke superpowers:systematic-debugging if Firebase-specific tools don't reveal root cause.
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright violations.
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.
Create beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.