HIVE

Local Setup

Troubleshooting

Troubleshooting

Common issues and solutions when developing with HIVE Protocol.

Quick Diagnostics

Run these commands to diagnose common issues:

# Check Node.js version
node --version  # Should be 18+

# Check npm version
npm --version   # Should be 9+

# Verify dependencies installed
ls node_modules | wc -l  # Should be 200+

# Check environment variables
cat .env | grep SUPABASE

# Test build
npm run build

# Check for TypeScript errors
npm run typecheck

Installation Issues

npm install Fails

Symptoms: Errors during npm install, missing packages

Solutions:

# Clear npm cache
npm cache clean --force

# Delete existing modules and lockfile
rm -rf node_modules package-lock.json

# Reinstall
npm install

# If still failing, try with legacy peer deps
npm install --legacy-peer-deps

Memory issues (large projects):

# Increase Node memory
export NODE_OPTIONS="--max-old-space-size=4096"
npm install

Node Version Mismatch

Symptoms: Syntax errors, unexpected token errors

Solutions:

# Check current version
node --version

# Switch to correct version with nvm
nvm install 20
nvm use 20

# Or use .nvmrc
echo "20" > .nvmrc
nvm use

Permission Errors (macOS/Linux)

Symptoms: EACCES errors

Solutions:

# Fix npm permissions (don't use sudo!)
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

# Or use nvm (recommended)
nvm install 20

Environment Issues

Environment Variables Not Loading

Symptoms: undefined values, connection failures

Checklist:

# 1. Verify .env file exists
ls -la .env

# 2. Check file format (no quotes around values)
cat .env

# 3. Correct format:
NEXT_PUBLIC_SUPABASE_URL=https://xxx.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJ...

# Wrong format:
NEXT_PUBLIC_SUPABASE_URL="https://xxx.supabase.co"  # No quotes!

Restart dev server after changes:

# Kill existing server (Ctrl+C) then:
npm run dev

NEXT_PUBLIC_ Variables Not Available

Symptoms: Variables undefined in browser

Cause: Only variables prefixed with NEXT_PUBLIC_ are exposed to the browser.

# Correct (available in browser)
NEXT_PUBLIC_SUPABASE_URL=https://xxx.supabase.co

# Wrong (only available server-side)
SUPABASE_URL=https://xxx.supabase.co

Database Issues

Cannot Connect to Supabase

Symptoms: Connection refused, timeout errors

Solutions:

# 1. Verify URL and key
echo $NEXT_PUBLIC_SUPABASE_URL
echo $NEXT_PUBLIC_SUPABASE_ANON_KEY

# 2. Test connection
curl https://your-project.supabase.co/rest/v1/ \
  -H "apikey: your-anon-key"

# 3. Check project status in Supabase dashboard
# Projects pause after 1 week of inactivity (free tier)

RLS Blocking Data Access

Symptoms: Queries return empty arrays, permission denied

Diagnosis:

-- Check RLS is enabled
SELECT tablename, rowsecurity
FROM pg_tables
WHERE schemaname = 'public';

-- Check policies exist
SELECT tablename, policyname
FROM pg_policies
WHERE schemaname = 'public';

Solutions:

-- Verify user is authenticated
-- In your code:
const { data: { user } } = await supabase.auth.getUser();
console.log('User:', user);  // Should not be null

-- Check if user matches policy
-- For "users can view own agents":
SELECT * FROM agents WHERE user_id = 'your-user-id';

Migration Errors

Symptoms: Tables missing, column errors

Solutions:

# Check migration status
supabase migration list

# Re-run failed migration manually in SQL Editor
# Copy SQL from supabase/migrations/xxx.sql

# Repair migration status
supabase migration repair --status applied 20260107174235

Authentication Issues

Login Not Working

Symptoms: Sign in fails, redirects back to login

Checklist:

  1. Check Supabase Auth settings (email enabled?)
  2. Verify redirect URLs configured
  3. Check browser console for errors
// Debug auth state
const { data, error } = await supabase.auth.signInWithPassword({
  email: 'test@example.com',
  password: 'password'
});

console.log('Auth result:', { data, error });

Session Not Persisting

Symptoms: User logged out on page refresh

Solutions:

// Ensure auth state listener is set up
useEffect(() => {
  const { data: { subscription } } = supabase.auth.onAuthStateChange(
    (event, session) => {
      console.log('Auth event:', event, session);
    }
  );

  return () => subscription.unsubscribe();
}, []);

Email Confirmation Required

Symptoms: "Email not confirmed" error

Solutions:

  1. Disable confirmation for development:
  2. Supabase Dashboard > Authentication > Settings
  3. Disable "Confirm Email"
  1. Or confirm manually:
UPDATE auth.users
SET email_confirmed_at = NOW()
WHERE email = 'test@example.com';

Build Issues

TypeScript Errors

Symptoms: Build fails with type errors

Solutions:

# Find all TypeScript errors
npm run typecheck

# Common fixes:

# 1. Missing types - add type annotations
const data: Agent[] = response.data;

# 2. Null checks
const name = agent?.name ?? 'Unknown';

# 3. Type assertions (use sparingly)
const data = response as AgentResponse;

Module Not Found

Symptoms: Cannot find module errors

Solutions:

# 1. Check import path
# Correct: import { Button } from '@/components/ui/button';
# Wrong:   import { Button } from 'components/ui/button';

# 2. Verify tsconfig paths
cat tsconfig.json | grep paths

# 3. Restart TypeScript server in VS Code
# Cmd+Shift+P > "TypeScript: Restart TS Server"

Build Memory Issues

Symptoms: JavaScript heap out of memory

Solutions:

# Increase Node memory for build
NODE_OPTIONS="--max-old-space-size=4096" npm run build

# Or in package.json:
"scripts": {
  "build": "NODE_OPTIONS='--max-old-space-size=4096' next build"
}

Runtime Issues

Hydration Mismatch

Symptoms: "Text content does not match" warning

Causes: Server/client rendering differences

Solutions:

// 1. Use useEffect for client-only code
const [mounted, setMounted] = useState(false);

useEffect(() => {
  setMounted(true);
}, []);

if (!mounted) return null;

// 2. Suppress hydration warning (last resort)
<div suppressHydrationWarning>{clientOnlyContent}</div>

Realtime Not Updating

Symptoms: Database changes not reflected in UI

Checklist:

// 1. Verify subscription is active
const channel = supabase
  .channel('test')
  .on('postgres_changes', { event: '*', schema: 'public', table: 'messages' },
    (payload) => console.log('Change:', payload)
  )
  .subscribe((status) => {
    console.log('Subscription status:', status);
  });

// 2. Check Replication settings in Supabase
// Database > Replication > Enable for table

// 3. Ensure table has RLS allowing select

API Rate Limiting

Symptoms: 429 Too Many Requests

Solutions:

// Implement retry with backoff
async function fetchWithRetry(url: string, options: RequestInit, retries = 3) {
  for (let i = 0; i < retries; i++) {
    const response = await fetch(url, options);

    if (response.status === 429) {
      const retryAfter = response.headers.get('Retry-After') || '60';
      await new Promise(r => setTimeout(r, parseInt(retryAfter) * 1000));
      continue;
    }

    return response;
  }
  throw new Error('Max retries exceeded');
}

Edge Function Issues

Function Returns 500

Symptoms: Internal server error from edge function

Debug:

# View function logs
supabase functions logs function-name --follow

# Common causes:
# 1. Missing environment variable
# 2. Invalid JSON parsing
# 3. Unhandled exception

CORS Errors

Symptoms: "Access-Control-Allow-Origin" errors

Solution: Ensure CORS headers in ALL responses:

const corsHeaders = {
  "Access-Control-Allow-Origin": "*",
  "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
  "Access-Control-Allow-Headers": "Content-Type, Authorization, X-Client-Info, Apikey",
};

// Handle OPTIONS preflight
if (req.method === "OPTIONS") {
  return new Response(null, { status: 200, headers: corsHeaders });
}

// Include in ALL responses
return new Response(data, {
  headers: { ...corsHeaders, "Content-Type": "application/json" }
});

Function Timeout

Symptoms: Function times out after 150s

Solutions:

// 1. Optimize slow operations
// 2. Use streaming for long responses
// 3. Break into smaller functions
// 4. Use background tasks for heavy work

Performance Issues

Slow Initial Load

Solutions:

// 1. Use dynamic imports
const HeavyComponent = dynamic(() => import('./HeavyComponent'), {
  loading: () => <Skeleton />
});

// 2. Optimize images
<Image src={url} width={400} height={300} loading="lazy" />

// 3. Reduce bundle size
npm run build
# Check output sizes

Memory Leaks

Symptoms: Growing memory usage, slowdowns

Solutions:

// Clean up subscriptions
useEffect(() => {
  const channel = supabase.channel('test').subscribe();

  return () => {
    supabase.removeChannel(channel);  // Cleanup!
  };
}, []);

// Clean up timers
useEffect(() => {
  const timer = setInterval(callback, 1000);
  return () => clearInterval(timer);  // Cleanup!
}, []);

Getting Help

Useful Commands

# Full system diagnostics
npm run typecheck && npm run lint && npm run build

# Reset everything
rm -rf node_modules .next package-lock.json
npm install
npm run dev

Log Locations

  • Browser Console: DevTools > Console
  • Server Logs: Terminal running npm run dev
  • Edge Function Logs: Supabase Dashboard > Edge Functions > Logs
  • Database Logs: Supabase Dashboard > Logs

Resources

  • [Supabase Discord](https://discord.supabase.com): Community support
  • [Next.js Docs](https://nextjs.org/docs): Framework documentation
  • [GitHub Issues](https://github.com/your-org/hive-protocol/issues): Bug reports
  • [Environment Setup](/docs/local-setup/environment-setup): Initial setup
  • [Supabase Setup](/docs/local-setup/supabase-setup): Database configuration
  • [Edge Functions](/docs/local-setup/edge-functions): Serverless functions

Cookie Preferences

We use cookies to enhance your experience, analyze site traffic, and for marketing purposes. By clicking "Accept All", you consent to our use of cookies. Read our Privacy Policy for more information.