Common issues and solutions for Crypto Data Aggregator.
Cause: Path alias not configured correctly.
Solution:
// tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}Cause: TypeScript type mismatch.
Solutions:
- Check the API response shape matches your types
- Add optional chaining:
data?.property - Update type definitions in
src/lib/market-data.ts
Cause: Using Node.js APIs in Edge Runtime.
Solution: Remove Node.js-only imports from API routes:
// ❌ Won't work in Edge Runtime
import fs from 'fs';
import path from 'path';
// ✅ Use Edge-compatible alternatives
// - fetch() for HTTP requests
// - In-memory Map for caching
// - External DB for persistenceCause: Build process ran out of memory.
Solution:
# Increase Node.js memory limit
NODE_OPTIONS="--max-old-space-size=4096" npm run buildCause: Server and client render different content.
Common Triggers:
- Using
Date.now()orMath.random()during render - Accessing
localStorageduring SSR - Browser-only APIs in server components
Solutions:
// ❌ Causes hydration mismatch
function Component() {
const time = Date.now(); // Different on server vs client
return <div>{time}</div>;
}
// ✅ Use useEffect for client-only values
function Component() {
const [time, setTime] = useState<number | null>(null);
useEffect(() => {
setTime(Date.now());
}, []);
if (time === null) return <Skeleton />;
return <div>{time}</div>;
}Cause: Accessing localStorage during server-side rendering.
Solution:
// ✅ Safe localStorage access
function getFromStorage(key: string): string | null {
if (typeof window === 'undefined') {
return null;
}
return localStorage.getItem(key);
}
// ✅ Or use useEffect
useEffect(() => {
const data = localStorage.getItem('key');
setData(data);
}, []);Cause: Accessing nested properties before data loads.
Solution:
// ❌ Unsafe
const price = data.market_data.current_price.usd;
// ✅ Safe with optional chaining
const price = data?.market_data?.current_price?.usd ?? 0;
// ✅ Or check before rendering
if (!data?.market_data) {
return <LoadingSpinner />;
}Cause: Hit external API rate limit.
Solutions:
- Wait and retry - CoinGecko limits reset per minute
- Increase cache TTL - Reduce API calls
- Use API key - Get higher limits with CoinGecko Pro
// Increase cache duration
newsCache.set(key, data, 600); // 10 minutes instead of 5Cause: CORS issue or network problem.
Diagnosis:
# Test API directly
curl https://api.coingecko.com/api/v3/ping
# Check from server
curl http://localhost:3000/api/market/coinsSolutions:
- Check internet connection
- Verify API is not down
- Check CORS configuration
- Try a different network
Cause: Aggressive caching.
Solutions:
// Force fresh data with SWR
const { mutate } = useSWR('/api/market/coins');
// Revalidate
mutate();
// Or clear server cache
newsCache.delete('latest');Cause: API returned no data or error was swallowed.
Debug:
export async function GET(request: Request) {
try {
const data = await fetchData();
console.log('API response:', data); // Add logging
return jsonResponse(data);
} catch (error) {
console.error('API error:', error); // Log full error
return errorResponse(error.message, 500);
}
}Checklist:
- HTTPS enabled (required for PWA)
- Valid
manifest.jsonat/manifest.json - Icons present (192x192 and 512x512)
- Service worker registered
-
start_urlaccessible
Debug:
// Check in browser console
navigator.serviceWorker.getRegistrations().then(console.log);Cause: Browser caching old service worker.
Solutions:
- Hard refresh: Cmd+Shift+R (Mac) / Ctrl+Shift+R (Windows)
- Unregister SW:
- DevTools → Application → Service Workers → Unregister
- Clear cache:
- DevTools → Application → Storage → Clear site data
Checklist:
- User granted permission
- Service worker active
- Push subscription created
- Valid VAPID keys (if using)
Debug:
// Check permission
console.log(Notification.permission);
// Check service worker
navigator.serviceWorker.ready.then((reg) => {
console.log('SW ready:', reg);
});Cause: Pages not cached.
Solutions:
- Visit pages while online first (to cache them)
- Check cache in DevTools → Application → Cache Storage
- Verify
sw.jshas correct cache strategies
Diagnosis:
# Analyze bundle size
npm run analyzeSolutions:
-
Dynamic imports for heavy components:
const HeavyChart = dynamic(() => import('./HeavyChart'), { loading: () => <Skeleton />, });
-
Reduce third-party scripts
-
Optimize images:
import Image from 'next/image'; <Image src={url} width={100} height={100} loading="lazy" />;
Cause: State updates after component unmounts.
Solution:
useEffect(() => {
let cancelled = false;
async function fetchData() {
const data = await getData();
if (!cancelled) {
setData(data);
}
}
fetchData();
return () => {
cancelled = true;
};
}, []);Diagnosis:
// Add to component
console.log('Render:', componentName);
// Or use React DevTools ProfilerSolutions:
- Memoize components:
React.memo() - Memoize values:
useMemo() - Memoize callbacks:
useCallback() - Split context to prevent unnecessary updates
Cause: localStorage full or blocked.
Diagnosis:
// Check localStorage usage
let total = 0;
for (let key in localStorage) {
if (localStorage.hasOwnProperty(key)) {
total += localStorage[key].length * 2; // UTF-16
}
}
console.log('localStorage used:', (total / 1024).toFixed(2), 'KB');Solutions:
- Clear unused data:
localStorage.removeItem('old_key') - Check if in private/incognito mode
- Check if localStorage is disabled
Cause: WebSocket disconnected or SWR not revalidating.
Solutions:
// Force refresh
const { mutate } = useSWR('/api/market/coins');
mutate();
// Check WebSocket status
const { isOnline } = usePWA();
console.log('Online:', isOnline);Cause: Coin not in CoinGecko database or ID mismatch.
Debug:
# Search for coin
curl "https://api.coingecko.com/api/v3/search?query=coinname"Solutions:
- Restart dev server:
npm run dev - Clear
.nextfolder:rm -rf .next - Check file is being watched (not in
.gitignore)
Common Fixes:
# Clear test cache
npx vitest --clearCache
# Run with verbose output
npx vitest --reporter=verbose
# Run single test
npx vitest -t "test name"Solution:
# Reset and reinstall
rm -rf node_modules package-lock.json
npm install
# Run format
npm run format
npm run lint:fixSolution:
# Rebuild TypeScript
npm run typecheck
# If tsconfig issues, regenerate
npx tsc --init
# Then restore your settingsBefore asking for help, gather:
# System info
node -v
npm -v
cat package.json | grep "next\|react"
# Error logs
npm run build 2>&1 | tail -50
# Network check
curl -I https://api.coingecko.com/api/v3/ping