This guide covers common issues encountered when setting up and running the NeuroWealth backend locally, with symptoms, root causes, and fix steps.
- Environment Variables
- Database Connectivity
- Prisma Schema Issues
- Health Check Failures
- Stellar Network Issues
- Build and Runtime Errors
- Test Failures
Error Message:
Application cannot start — environment configuration errors:
- Missing required environment variable: STELLAR_NETWORK
- Missing required environment variable: DATABASE_URL
...
Root Cause: Required environment variables are not set in .env file or shell environment.
Fix Steps:
-
Copy the example environment file:
cp .env.example .env
-
Edit
.envand fill in all required variables:# Required variables STELLAR_NETWORK=testnet STELLAR_RPC_URL=https://soroban-testnet.stellar.org STELLAR_AGENT_SECRET_KEY=SXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX VAULT_CONTRACT_ID=CXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX USDC_TOKEN_ADDRESS=CXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ANTHROPIC_API_KEY=sk-ant-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx DATABASE_URL=postgresql://postgres:password@localhost:5432/neurowealth JWT_SEED=your_jwt_secret_seed_here_minimum_32_characters WALLET_ENCRYPTION_KEY=generate_with_openssl_rand_hex_32 TWILIO_AUTH_TOKEN=your_twilio_auth_token_here NODE_ENV=development -
Generate secure values where needed:
# Generate wallet encryption key (64 hex chars) openssl rand -hex 32 # Generate JWT seed (48 base64 chars) openssl rand -base64 48
-
Restart the application:
npm run dev
Error Message:
WALLET_ENCRYPTION_KEY is invalid: must be exactly 64 hexadecimal characters (32 bytes).
Got length 32. Generate one with: openssl rand -hex 32
Root Cause: Wallet encryption key is not 64 hexadecimal characters.
Fix Steps:
-
Generate a valid key:
openssl rand -hex 32
-
Update
.envwith the generated value:WALLET_ENCRYPTION_KEY=a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2
-
Restart the application.
Error Message:
JWT_SEED is too weak: must be at least 32 characters.
Got length 16. Use a strong random string or generate with: openssl rand -base64 48
Root Cause: JWT seed is too short for cryptographic security.
Fix Steps:
-
Generate a strong seed:
openssl rand -base64 48
-
Update
.envwith the generated value (minimum 32 characters). -
Restart the application.
Error Message:
ANTHROPIC_API_KEY is invalid: must start with "sk-ant-".
Got prefix "sk-proj-". Get your key from: https://console.anthropic.com/
Root Cause: Invalid Anthropic API key format.
Fix Steps:
- Get a valid API key from https://console.anthropic.com/
- Ensure the key starts with
sk-ant- - Update
.envwith the correct key.
Error Message:
DATABASE_URL is invalid: must start with "postgresql://" or "postgres://".
Got: "mysql://user:pass@localhost:3306/dbname". Example: postgresql://user:pass@localhost:5432/dbname
Root Cause: Invalid database connection string format.
Fix Steps:
- Ensure you're using PostgreSQL (not MySQL)
- Use the correct format:
DATABASE_URL=postgresql://user:password@localhost:5432/dbname
- If using Docker Compose, use the service name as host:
DATABASE_URL=postgresql://postgres:password@neurowealth_db:5432/postgres
Error Message:
Error: connect ECONNREFUSED 127.0.0.1:5432
Root Cause: PostgreSQL is not running or not accessible.
Fix Steps:
Option A: Using Docker Compose
-
Start the database:
docker-compose up -d
-
Verify it's running:
docker-compose ps
-
Check logs:
docker-compose logs db
Option B: Using Local PostgreSQL
-
Ensure PostgreSQL is installed and running:
# macOS brew services start postgresql # Linux sudo systemctl start postgresql # Windows # Start PostgreSQL Service from Services
-
Verify connection:
psql -U postgres -d neurowealth
-
Create database if it doesn't exist:
psql -U postgres -c "CREATE DATABASE neurowealth;"
Error Message:
Error: password authentication failed for user "postgres"
Root Cause: Incorrect database credentials in DATABASE_URL.
Fix Steps:
-
Verify your PostgreSQL credentials:
psql -U postgres -d neurowealth
-
Update
.envwith correct credentials:DATABASE_URL=postgresql://postgres:CORRECT_PASSWORD@localhost:5432/neurowealth
-
If using Docker Compose, check
docker-compose.ymlfor the correct password:grep POSTGRES_PASSWORD docker-compose.yml
Error Message:
Error: database "neurowealth" does not exist
Root Cause: Database hasn't been created.
Fix Steps:
-
Create the database:
psql -U postgres -c "CREATE DATABASE neurowealth;" -
Or use Docker Compose (creates database automatically):
docker-compose up -d
Error Message:
Error: P3006
Migration `20260326152030_add_event_tracking` failed to apply cleanly to the shadow database.
Root Cause: Prisma schema is out of sync with the database.
Fix Steps:
-
Generate Prisma client:
npx prisma generate
-
Check migration status:
npx prisma migrate status
-
Apply pending migrations:
npx prisma migrate deploy
-
If migrations fail, reset (WARNING: destroys data):
npx prisma migrate reset
Error Message:
Error: P3001
Migration did not apply cleanly
Root Cause: Migration conflicts or manual schema changes.
Fix Steps:
-
Resolve the specific migration issue by checking the migration SQL:
cat prisma/migrations/*/migration.sql -
If the migration was already applied manually, mark it as applied:
npx prisma migrate resolve --applied "migration_name" -
If the migration needs to be rolled back:
npx prisma migrate resolve --rolled-back "migration_name" -
Re-run migrations:
npx prisma migrate deploy
Error Message:
error TS2339: Property 'id' does not exist on type 'User'
Root Cause: Prisma client not generated after schema changes.
Fix Steps:
-
Regenerate Prisma client:
npx prisma generate
-
If that fails, clean and regenerate:
rm -rf node_modules/.prisma npx prisma generate
-
Restart TypeScript server in your IDE (Cmd+Shift+P → "TypeScript: Restart TS Server")
Error Message:
{
"status": "not_ready",
"services": {
"database": { "ready": false, "error": "Connection refused" },
"eventListener": { "ready": true },
"agentLoop": { "ready": true }
}
}Root Cause: One or more critical services failed to initialize.
Fix Steps:
-
Check which service is failing:
curl http://localhost:3001/health/ready
-
Check application logs for the specific error:
# If using file logging tail -f logs/combined.log # If using console output npm run dev
-
Common fixes by service:
- database: Fix
DATABASE_URL, ensure PostgreSQL is running - eventListener: Check
STELLAR_RPC_URLconnectivity - agentLoop: Check Stellar agent key and contract ID
- database: Fix
Root Cause: Application is not running or crashed.
Fix Steps:
-
Check if the process is running:
ps aux | grep node -
Check if the port is in use:
lsof -i :3001
-
Kill any existing process on port 3001:
kill -9 $(lsof -t -i:3001)
-
Restart the application:
npm run dev
Error Message:
STELLAR_AGENT_SECRET_KEY must start with S (invalid Stellar secret key format)
Root Cause: Invalid Stellar secret key format.
Fix Steps:
-
Generate a valid Stellar keypair using Stellar SDK:
# Using stellar-cli stellar keys generate my-key # Or use the SDK npx ts-node -e "import { Keypair } from '@stellar/stellar-sdk'; const kp = Keypair.random(); console.log('Secret:', kp.secret()); console.log('Public:', kp.publicKey());"
-
Update
.envwith the generated secret key (starts with 'S', 56 characters). -
Ensure the key has sufficient XLM balance on the target network.
Error Message:
Error: fetch failed - timeout connecting to https://soroban-testnet.stellar.org
Root Cause: Network connectivity issues or RPC server down.
Fix Steps:
-
Test RPC connectivity:
curl -X POST https://soroban-testnet.stellar.org \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":1,"method":"getLatestLedger"}'
-
If RPC is down, use an alternative:
# Testnet alternatives STELLAR_RPC_URL=https://soroban-testnet.stellar.org STELLAR_RPC_URL=https://testnet.rpc.sorobanrpc.com -
Check your internet connection and firewall settings.
Error Message:
Error: Invalid contract ID format
Root Cause: Contract ID doesn't match Stellar contract ID format.
Fix Steps:
-
Ensure contract ID starts with 'C' and is 56 alphanumeric characters:
VAULT_CONTRACT_ID=CXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-
Verify the contract ID matches your deployed contract on the target network.
-
Check network alignment (testnet vs mainnet):
STELLAR_NETWORK=testnet # or mainnet
Error Message:
error TS2307: Cannot find module './config' or its corresponding type declarations
Root Cause: Missing dependencies or incorrect import paths.
Fix Steps:
-
Install dependencies:
npm install
-
Clean and rebuild:
rm -rf dist node_modules npm install npm run build
-
Check TypeScript configuration:
npx tsc --noEmit
Error Message:
Error: Cannot find module '@prisma/client'
Root Cause: Prisma client not generated.
Fix Steps:
-
Generate Prisma client:
npx prisma generate
-
Reinstall dependencies:
rm -rf node_modules package-lock.json npm install
Error Message:
Error: listen EADDRINUSE: address already in use :::3001
Root Cause: Another process is using port 3001.
Fix Steps:
-
Find and kill the process:
# Find process lsof -i :3001 # Kill it kill -9 $(lsof -t -i:3001)
-
Or use a different port:
PORT=3002 npm run dev
Error Message:
Error: connect ECONNREFUSED 127.0.0.1:5432
Root Cause: Test database not running or misconfigured.
Fix Steps:
-
Ensure test database is running (Docker Compose):
docker-compose up -d
-
Set test environment variables:
export NODE_ENV=test export DATABASE_URL=postgresql://postgres:password@localhost:5432/neurowealth_test
-
Run migrations on test database:
npx prisma migrate deploy
Root Cause: Tests waiting for async operations or external services.
Fix Steps:
- Check for missing async/await in tests
- Mock external service calls (Stellar RPC, Anthropic API)
- Increase test timeout in jest config:
# Add to package.json jest config "testTimeout": 10000
Error Message:
Error: Cannot find module '../src/config/env'
Root Cause: Incorrect import paths in test files.
Fix Steps:
- Use correct relative paths from
tests/directory - Or configure TypeScript path mapping in
tsconfig.json - Ensure source files are compiled before running tests:
npm run build npm test
If you've tried the above steps and still can't resolve the issue:
-
Check the logs:
tail -f logs/combined.log tail -f logs/error.log
-
Verify your environment:
node --version # Should be 20+ npm --version # Should be 10+ psql --version # Should be 14+
-
Search existing issues: Check GitHub Issues for similar problems
-
Create a detailed bug report including:
- Error message (full stack trace)
- Environment (OS, Node version, PostgreSQL version)
- Steps to reproduce
- What you've already tried
# Environment setup
cp .env.example .env
openssl rand -hex 32 # Generate wallet encryption key
openssl rand -base64 48 # Generate JWT seed
# Database operations
docker-compose up -d # Start database
npx prisma generate # Generate Prisma client
npx prisma migrate deploy # Apply migrations
npx prisma migrate status # Check migration status
npx prisma migrate reset # Reset database (WARNING: destroys data)
# Health checks
curl http://localhost:3001/health/live
curl http://localhost:3001/health/ready
# Build and run
npm install
npm run build
npm run dev
# Tests
npm test
npm run test:unit
npm run test:integration