Troubleshooting Guide
Solutions to common issues and problems when installing and using SveltyCMS.
Last updated: 10/5/2025
Troubleshooting Guide
Common issues and solutions for SveltyCMS installation and usage.
Installation Issues
Issue: “Cannot find module” errors
Symptoms:
Error: Cannot find module 'mongoose'
Error: Cannot find module 'mariadb'
Solution:
-
Install missing database driver:
# MongoDB npm install mongoose # MariaDB/MySQL npm install mariadb # PostgreSQL npm install pg -
Or use the CLI installer:
npm run dev # Follow prompts to auto-install drivers -
Clear cache and reinstall:
rm -rf node_modules package-lock.json npm install
Issue: Port 5173 already in use
Symptoms:
Error: listen EADDRINUSE: address already in use :::5173
Solution:
-
Find and kill the process:
# macOS/Linux lsof -ti:5173 | xargs kill -9 # Windows netstat -ano | findstr :5173 taskkill /PID <PID> /F -
Or use a different port:
PORT=3000 npm run dev -
Update vite.config.ts:
export default defineConfig({ server: { port: 3000 } });
Issue: Database connection failed
Symptoms:
MongoDB connection failed: Authentication failed
MariaDB connection failed: Access denied
Solutions:
MongoDB
-
Check credentials:
DB_USER=admin DB_PASSWORD=correct_password -
Verify MongoDB is running:
# macOS/Linux sudo systemctl status mongod # Or check if listening nc -zv localhost 27017 -
Check MongoDB Atlas whitelist:
- Login to MongoDB Atlas
- Network Access → Add IP Address
- Add
0.0.0.0/0(for development only!)
-
Fix connection string format:
# Local DB_HOST=localhost DB_PORT=27017 # Atlas DB_HOST=mongodb+srv://cluster.mongodb.net # Note: No port needed for Atlas
MariaDB/MySQL
-
Verify service is running:
sudo systemctl status mariadb # or sudo systemctl status mysql -
Test connection manually:
mysql -h localhost -u root -p -
Grant permissions:
GRANT ALL PRIVILEGES ON sveltycms.* TO 'admin'@'localhost'; FLUSH PRIVILEGES; -
Check firewall:
# Allow MySQL port sudo ufw allow 3306
Issue: CLI installer not launching
Symptoms:
- Development server starts but no setup wizard appears
Solution:
-
Manually run installer:
npm run installer -
Or navigate to setup page:
http://localhost:5173/setup -
Check if already installed:
- If
.envfile exists, setup is skipped - Delete
.envto re-run setup (CAUTION: Will lose config)
- If
Runtime Issues
Issue: “Unauthorized” errors
Symptoms:
{
"error": "Unauthorized"
}
Solutions:
-
Clear browser cookies:
- Open DevTools → Application → Cookies
- Delete
sessioncookie - Refresh and login again
-
Check session secret:
SESSION_SECRET=your-secret-here- Must be set and consistent
- Generate new:
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
-
Verify JWT secret:
JWT_SECRET=your-jwt-secret -
Check token expiration:
- Default: 24 hours
- Login again to refresh
Issue: “Cannot read properties of undefined”
Symptoms:
TypeError: Cannot read properties of undefined (reading 'user')
Solutions:
-
Check hooks.server.ts:
- Ensure authentication hooks are registered
- Verify
locals.useris set
-
Restart development server:
# Stop server (Ctrl+C) npm run dev -
Clear build cache:
rm -rf .svelte-kit npm run dev
Issue: 404 on API endpoints
Symptoms:
404 Not Found: /api/collections/posts
Solutions:
-
Check route file exists:
ls src/routes/api/collections/[collectionId]/+server.ts -
Verify SvelteKit routing:
- Folder names must match route params
+server.tsrequired for API endpoints
-
Check base URL:
// ✅ Correct fetch('/api/collections/posts'); // ❌ Wrong fetch('api/collections/posts'); // Missing leading / -
Restart server:
npm run dev
Issue: Database queries returning empty results
Symptoms:
- Collections exist but queries return
[] - Dashboard shows 0 entries
Solutions:
-
Check tenant ID (multi-tenant mode):
// Queries automatically scoped by tenant // Verify user is in correct tenant console.log(locals.tenantId); -
Verify data was seeded:
# Check database directly # MongoDB mongo sveltycms db.posts.find() # MySQL mysql -u root -p USE sveltycms; SELECT * FROM posts; -
Check collection name:
- Collection names are case-sensitive
- Use exact name from schema
-
Verify permissions:
- User may not have
readpermission - Check role permissions in Settings
- User may not have
Issue: File upload fails
Symptoms:
Error: File size exceeds maximum allowed size
Error: File type not allowed
Solutions:
-
Check file size limits:
# .env MAX_FILE_SIZE=10485760 # 10MB in bytes -
Verify allowed file types:
- Go to Settings → Media
- Check allowed extensions
- Add missing types
-
Check disk space:
df -h -
Verify upload directory permissions:
chmod -R 755 static/uploads chown -R $USER:$USER static/uploads -
Check Nginx/Apache limits:
# Nginx client_max_body_size 50M;# Apache LimitRequestBody 52428800
Performance Issues
Issue: Slow API responses
Symptoms:
- API requests take > 1 second
- Dashboard loads slowly
Solutions:
-
Enable caching:
CACHE_ENABLED=true USE_REDIS=false # Or true if Redis available -
Add database indexes:
// MongoDB db.posts.createIndex({ title: 'text', content: 'text' }); db.posts.createIndex({ createdAt: -1 }); -
Limit query results:
// Use pagination fetch('/api/collections/posts?limit=25&page=1'); -
Optimize images:
- Use WebP format
- Enable image processing
- Implement lazy loading
-
Check database connection:
- Use connection pooling
- Reduce connection timeout
- Monitor active connections
Issue: High memory usage
Symptoms:
JavaScript heap out of memory
FATAL ERROR: Reached heap limit
Solutions:
-
Increase Node memory:
NODE_OPTIONS="--max-old-space-size=4096" npm run dev -
Add to package.json:
{ "scripts": { "dev": "NODE_OPTIONS='--max-old-space-size=4096' vite dev" } } -
Clear cache:
# Clear application cache curl -X POST http://localhost:5173/api/cache/clear \ -H "Cookie: session=your-session" -
Optimize queries:
- Use pagination
- Limit field selection
- Avoid loading large datasets
Build & Deployment Issues
Issue: Build fails with TypeScript errors
Symptoms:
Type error: Property 'user' does not exist on type 'Locals'
Solutions:
-
Update app.d.ts:
// src/app.d.ts declare global { namespace App { interface Locals { user: import('$lib/types').User | null; tenantId: string; } } } -
Run type check:
npm run typecheck -
Install missing types:
npm install --save-dev @types/node
Issue: Production build too large
Symptoms:
- Build size > 5MB
- Slow page loads
Solutions:
-
Enable code splitting:
// vite.config.ts export default defineConfig({ build: { rollupOptions: { output: { manualChunks: { vendor: ['svelte'], utils: ['./src/utils'] } } } } }); -
Remove unused dependencies:
npx depcheck -
Analyze bundle:
npm run build -- --analyze -
Use dynamic imports:
// Instead of import Widget from './Widget.svelte'; // Use const Widget = await import('./Widget.svelte');
Issue: Environment variables not loaded
Symptoms:
process.env.DB_HOSTis undefined- Settings not applied in production
Solutions:
-
Check .env file location:
# Must be in project root ls -la .env -
Verify variable names:
# Public variables need PUBLIC_ prefix PUBLIC_SITE_NAME=My CMS # Private variables DB_PASSWORD=secret -
Restart server after .env changes:
npm run dev -
Load .env explicitly (if needed):
import 'dotenv/config';
Common Error Messages
“ECONNREFUSED”
Meaning: Cannot connect to database
Fix:
- Verify database is running
- Check host and port in
.env - Verify firewall rules
“CORS Error”
Meaning: Cross-origin request blocked
Fix:
// svelte.config.js
export default {
kit: {
cors: {
origin: ['http://localhost:3000'],
credentials: true
}
}
};
“MongoServerError: Authentication failed”
Meaning: Wrong MongoDB credentials
Fix:
- Double-check username/password
- Verify authentication database
- Check user permissions
“ER_ACCESS_DENIED_ERROR”
Meaning: MySQL/MariaDB access denied
Fix:
-- Grant permissions
GRANT ALL PRIVILEGES ON sveltycms.* TO 'user'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
Widget Issues
Issue: Widget Dashboard Shows Wrong Counts
Symptoms:
- Custom widgets appear in dropdowns and work correctly
- Dashboard shows “0” custom widgets
- File system shows widgets exist in
src/widgets/ - Database sync button available
Understanding the Dual-Layer System:
SveltyCMS uses a dual-layer widget system:
-
File System Layer (
src/widgets/):- Widgets physically exist as
.sveltefiles - Used directly by the application at runtime
- Works immediately without database registration
- Widgets physically exist as
-
Database Layer (MongoDB
widgetscollection):- Stores widget metadata for dashboard and management
- Required for accurate dashboard counts
- Enables widget discovery and categorization
Why This Happens:
Custom widgets in src/widgets/Display/, src/widgets/Definition/, and src/widgets/Input/ work immediately because the application loads them directly from the file system. However, the dashboard counts widgets from the database, which may not reflect recent file system changes.
Solutions:
1. Use the Sync Button
The dashboard provides a “Sync Widgets” button that:
- Scans
src/widgets/for all widget files - Compares with database records
- Adds new widgets to the database
- Updates widget counts in the dashboard
To sync:
- Go to Dashboard → Widgets
- Click “Sync Widgets” button
- Wait for confirmation
- Refresh to see updated counts
2. Use the API Endpoint
# Trigger widget sync via API
curl -X POST http://localhost:5173/api/widgets/sync \
-H "Cookie: session=your-session"
Response:
{
"success": true,
"added": 5,
"updated": 2,
"message": "Widgets synchronized successfully"
}
3. Manual Database Sync
# MongoDB
mongosh sveltycms
db.widgets.find({ type: "custom" }).count()
# Insert missing widget manually
db.widgets.insertOne({
name: "CustomWidget",
type: "custom",
category: "Display",
path: "src/widgets/Display/CustomWidget.svelte",
enabled: true,
createdAt: new Date()
})
Common Scenarios:
-
New Custom Widget Created:
- Widget works in collections immediately
- Dashboard shows old count
- Fix: Click “Sync Widgets”
-
Widget Deleted from File System:
- Database still has reference
- Dashboard shows incorrect count
- Fix: Sync to clean up orphaned entries
-
Widget Renamed:
- Old name in database
- New file in file system
- Fix: Sync to update database record
-
Fresh Installation:
- Core widgets exist in files
- Database empty or partially populated
- Fix: Run sync on first setup
Best Practices:
- After adding custom widgets: Always run sync
- After git pull: Sync to update database with new widgets
- Regular maintenance: Sync monthly to keep database clean
- CI/CD: Include widget sync in deployment scripts
# Add to deployment script
npm run build
npm run db:migrate
npm run widgets:sync # Custom script to call sync endpoint
Preventing Issues:
-
Use Widget Generator CLI:
npm run widget:create # Automatically registers in database -
Enable Auto-Sync (if configured):
WIDGET_AUTO_SYNC=true # Syncs on server start -
Monitor Logs:
tail -f logs/app.log | grep "widget"
Issue: Custom Widget Not Appearing in Collection Builder
Symptoms:
- Widget file exists in
src/widgets/ - Widget works when hardcoded
- Not visible in collection builder dropdown
Solutions:
-
Sync widgets to database:
- Click “Sync Widgets” in dashboard
- Widget must be registered in database to appear in builder
-
Check widget export:
// ✅ Correct export default MyWidget; // ❌ Wrong export { MyWidget }; // Named export not supported -
Verify widget category:
- Display widgets go in
src/widgets/Display/ - Input widgets go in
src/widgets/Input/ - Definition widgets go in
src/widgets/Definition/
- Display widgets go in
-
Check widget metadata:
<script lang="ts"> // Widget metadata for registration export const metadata = { name: 'MyWidget', category: 'Display', description: 'My custom widget' }; </script> -
Restart development server:
npm run dev
Issue: Widget Fails to Load
Symptoms:
Failed to load widget: Cannot find module './widgets/CustomWidget.svelte'
Error: Widget 'CustomWidget' not found
Solutions:
-
Check file path and naming:
# Widget filename must match registration ls src/widgets/Display/CustomWidget.svelte -
Verify import in widget factory:
// src/widgets/widgetFactory.ts const displayWidgets = { CustomWidget: () => import('./Display/CustomWidget.svelte') }; -
Check widget is enabled:
// Database check db.widgets.findOne({ name: 'CustomWidget' }); // Verify: { enabled: true } -
Clear build cache:
rm -rf .svelte-kit npm run dev
Issue: Widget Props Not Working
Symptoms:
- Widget renders but props undefined
- Console error: “Cannot read property of undefined”
Solutions:
-
Define props with proper types:
<script lang="ts"> import type { WidgetProps } from '$lib/types'; export let data: WidgetProps['data']; export let config: WidgetProps['config'] = {}; export let mode: WidgetProps['mode'] = 'display'; </script> -
Provide default values:
<script lang="ts"> export let title: string = 'Default Title'; export let count: number = 0; </script> -
Check parent component:
<!-- ✅ Correct --> <Widget {data} {config} mode="edit" /> <!-- ❌ Wrong --> <Widget {data} /> <!-- Missing other required props -->
Getting More Help
Debug Mode
Enable verbose logging:
LOG_LEVEL=debug
DEBUG=sveltycms:*
Check System Requirements
# Node version
node --version # Should be >= 20.10.0
# npm version
npm --version
# Git version
git --version
# Database version
mongo --version # MongoDB
mysql --version # MySQL/MariaDB
Collect Debug Information
Before reporting issues, collect:
# System info
node --version
npm --version
cat package.json | grep version
# Error logs
cat logs/app.log
# Environment (without secrets!)
cat .env | grep -v PASSWORD | grep -v SECRET
Report an Issue
Include in your bug report:
-
Environment:
- OS (Windows/macOS/Linux)
- Node version
- Package manager (npm/bun/yarn)
- Database type and version
-
Steps to reproduce:
- What you did
- What you expected
- What actually happened
-
Error messages:
- Full error text
- Stack trace
- Console output
-
Screenshots:
- Error screens
- Console errors
- Network tab
Submit issues: GitHub Issues