Troubleshooting
Common issues you might encounter when deploying and running Pixelflare, with their solutions.
Deployment Errors
Missing Required Tools
Error: command not found: terraform (or wrangler, jq, curl)
Cause: Required CLI tools not installed.
Solution:
# macOS
brew install terraform wrangler jq curl
# Linux (Debian/Ubuntu)
sudo apt install jq curl
npm install -g wrangler
# Install Terraform from https://terraform.io/downloadsMissing Environment Variables
Error: CLOUDFLARE_API_TOKEN not set or is placeholder
Cause: .env file missing or contains placeholder values.
Solution:
- Copy
.env.exampleto.env - Fill in
CLOUDFLARE_API_TOKEN,CLOUDFLARE_ACCOUNT_ID, andDOMAIN - Get API token from Cloudflare Dashboard
Invalid API Token
Error: API token validation failed or Error: failed to fetch account
Cause: API token is invalid, expired, or has insufficient permissions.
Solution:
- Create new API token with all required permissions (see deployment guide)
- Update
CLOUDFLARE_API_TOKENin.env - Ensure token includes Account and Zone permissions
Domain Not Found in Cloudflare
Error: Domain example.com not found in Cloudflare account
Cause: Domain hasn't been added to your Cloudflare account.
Solution:
- Go to Cloudflare Dashboard
- Add your domain
- Update nameservers at your domain registrar
- Wait for DNS to propagate (status should be "Active")
Terraform State Lock
Error: Error acquiring the state lock
Cause: Previous Terraform run didn't complete or crashed.
Solution:
cd terraform
terraform force-unlock <lock-id>Replace <lock-id> with the ID shown in the error message.
Resource Already Exists
Error: Error: resource already exists
Cause: Terraform trying to create a resource that already exists from previous run.
Solution:
# Import existing resource
terraform import <resource_type>.<name> <id>
# Example for Worker script:
terraform import module.workers.cloudflare_workers_script.api <script-id>Terraform Not Initialized
Error: Error: Could not load plugin or Terraform has not been initialized
Cause: Terraform providers haven't been downloaded.
Solution:
cd terraform
terraform initTerraform Version Mismatch
Error: Error: Unsupported Terraform Core version
Cause: Terraform version is too old (requires >= 1.5.0).
Solution:
# Check version
terraform version
# Upgrade Terraform
# macOS: brew upgrade terraform
# Linux: Download from https://terraform.io/downloadsCloudflare Provider Version Issues
Error: Error: Failed to query available provider packages
Cause: Cloudflare provider version incompatible or download failed.
Solution:
cd terraform
rm -rf .terraform .terraform.lock.hcl
terraform initInvalid Environment Variable
Error: Environment must be one of: dev, staging, production
Cause: ENVIRONMENT variable has invalid value in .env.
Solution: Set ENVIRONMENT=production (or dev/staging) in .env file.
Invalid Auth Mode
Error: auth_mode must be one of: none, cloudflare, authjs
Cause: AUTH_MODE variable has invalid value.
Solution: Set AUTH_MODE=cloudflare (or authjs/none) in .env file.
Queues Without Paid Plan
Error: Queues created but not working, or queue consumer errors.
Cause: Cloudflare Queues require Workers Paid plan ($5/month).
Solution:
- Upgrade to Workers Paid in Cloudflare Dashboard
- Or disable queues: Set
ENABLE_QUEUES=falsein.envand redeploy - Note: Without queues, image variants won't be generated automatically
Terraform Worker Script Read Error
Error: Error reading worker script from API: unexpected EOF
Cause: Intermittent Cloudflare API issue during state refresh.
Solution: Simply retry the deployment - this is a transient error:
make deployWrangler Config Not Found
Error: Error: Wrangler config not found: packages/api/wrangler.production.toml
Cause: Terraform didn't generate wrangler configs or step was skipped.
Solution:
# Regenerate configs
./scripts/tasks/05-generate-wrangler-config.cjs productionDatabase Migrations Failed
Error: Migrations not applied or schema errors.
Cause: D1 database created but migrations didn't run.
Solution:
# Check migration status
wrangler d1 migrations list pixflare-production-db --config packages/api/wrangler.production.toml
# Apply migrations
wrangler d1 migrations apply pixflare-production-db --config packages/api/wrangler.production.toml --remoteSecrets Not Set
Error: Worker deployment succeeds but app doesn't work properly.
Cause: Required secrets weren't uploaded to Workers.
Solution:
# Re-run secrets setup
./scripts/tasks/12-set-secrets.sh production
# Verify secrets are set
wrangler secret list --config packages/api/wrangler.production.tomlPages Deployment Failed
Error: Frontend build or deployment fails.
Cause: Build errors, missing dependencies, or Pages configuration issues.
Solution:
# Check build locally first
cd packages/frontend
pnpm build
# View deployment logs
wrangler pages deployment tail --project-name pixflare-frontendRuntime Errors
Unable to Login / Redirect Loop
Error: Clicking "Sign In" redirects back to login page repeatedly.
Cause: OAuth configuration mismatch or Cloudflare Access misconfigured.
Solution:
- Verify GitHub OAuth callback URL matches:bash
terraform output github_callback_url - Check callback URL in GitHub OAuth app settings
- Verify
CF_ACCESS_AUDmatches Access application:bashterraform output cf_access_aud - Check Cloudflare Access policies allow your email/domain
403 Forbidden After Login
Error: Authenticated but can't access the app.
Cause: Cloudflare Access policy too restrictive.
Solution:
- Go to Zero Trust → Access → Applications
- Find your Pixelflare application
- Edit policy to allow your email or GitHub organization
- Save and wait 1-2 minutes for propagation
Images Not Loading
Error: Upload works but images don't display (404 or broken images).
Cause: R2 bucket access issues or CDN routing problems.
Solution:
- Check image exists in R2:
- Go to R2 Dashboard → Your bucket
- Verify files are present
- Check worker logs for errors:bash
wrangler tail --config packages/api/wrangler.production.toml - Verify DNS records are correct:
api.yourdomain.com→ Worker routecdn.yourdomain.com→ Worker route (or R2 custom domain)
Upload Fails with "Invalid Upload Token"
Error: 401 Unauthorized when uploading images.
Cause: UPLOAD_TOKEN_SECRET missing or mismatched.
Solution:
# Generate new secret
openssl rand -hex 32 | wrangler secret put UPLOAD_TOKEN_SECRET --config packages/api/wrangler.production.toml
# Or use existing from .env
echo "$UPLOAD_TOKEN_SECRET" | wrangler secret put UPLOAD_TOKEN_SECRET --config packages/api/wrangler.production.tomlFile Too Large Error
Error: 413 Payload Too Large or "File is too large".
Cause: File exceeds 100MB upload limit.
Solution:
- Compress image before upload
- Maximum file size is 100MB (Cloudflare Workers limit)
- For larger files, consider resizing or using a different format
Rate Limit Exceeded
Error: 429 Too Many Requests.
Cause: Hit rate limit for uploads or API calls.
Solution:
- Wait 60 seconds and try again
- Upload rate limits reset per minute
- For production use, consider adjusting limits in code or enabling Stripe billing
Database Connection Errors
Error: 500 errors with "D1 binding not found" in logs.
Cause: D1 database binding not configured in wrangler.toml.
Solution:
# Regenerate wrangler config
./scripts/tasks/05-generate-wrangler-config.cjs production
# Verify binding exists
cat packages/api/wrangler.production.toml | grep -A 3 "d1_databases"AI Features Not Working
Error: "AI analysis is not enabled for this instance".
Cause: ENABLE_AI_CLASSIFICATION disabled or AI binding missing.
Solution:
- Set
ENABLE_AI_CLASSIFICATION=truein.env - Redeploy:
make deploy - Verify AI binding in wrangler.toml:bash
cat packages/api/wrangler.production.toml | grep -A 2 "ai ="
Custom Domains Not Working
Error: "Custom domains feature not enabled".
Cause: Feature flag disabled or Cloudflare zone configuration missing.
Solution:
- Set
ENABLE_CUSTOM_DOMAINS=truein.env - Set
CLOUDFLARE_ZONE_IDin.env - Redeploy workers
- Custom domains require SSL/TLS Full mode in Cloudflare
Queue Processing Stuck
Error: Images uploaded but variants never generated.
Cause: Queue consumer not running or queue binding missing.
Solution:
- Check queue exists:
- Go to Queues Dashboard → Your account → Queues
- Verify queue binding in wrangler.toml
- Check worker logs for queue consumer errors:bash
wrangler tail --config packages/api/wrangler.production.toml - Queues require Workers Paid plan ($5/month)
Configuration Issues
CORS Errors in Browser
Error: "blocked by CORS policy" in browser console.
Cause: API_HOST or APP_HOST environment variables incorrect.
Solution:
- Verify
API_HOSTmatches your API worker URL - Verify
APP_HOSTmatches your frontend URL - Check
FRONTEND_HOSTis set correctly - Redeploy workers after fixing
TypeScript Build Errors
Error: Build fails with type errors.
Cause: Dependencies out of sync or breaking changes.
Solution:
# Clean install
pnpm install
# Run type check
pnpm type-check
# Build packages in order
pnpm --filter @pixflare/shared --filter @pixflare/config build
pnpm buildEnvironment Variable Not Taking Effect
Error: Changed .env but app still uses old value.
Cause: Terraform variables not regenerated or worker not redeployed.
Solution:
# Regenerate Terraform variables
./scripts/tasks/02-env-to-tfvars.cjs
# Apply Terraform changes
cd terraform && terraform apply
# Regenerate wrangler config
./scripts/tasks/05-generate-wrangler-config.cjs production
# Redeploy workers
make deploy-workersPerformance Issues
Slow Image Loading
Cause: No caching or variants not being used.
Solution:
- Enable Cloudflare cache on your zone
- Use variant URLs instead of original:
/cdn/user/album/image.jpg?w=800 - Check KV cache is enabled (should be automatic)
High R2 Costs
Cause: Lots of Class A operations (PUT/DELETE) or egress.
Solution:
- Enable variant generation to reduce original image fetches
- Use Cloudflare cache to reduce R2 reads
- Consider enabling R2 custom domain for built-in image resizing
Getting Help
Still stuck?
- Check GitHub Discussions for similar issues
- Review deployment logs for specific error messages
- Search existing issues
- Open a new issue with:
- Error message (full text)
- Steps to reproduce
- Your environment (OS, Node version, etc.)
- Relevant logs (redact secrets!)