Add configuration for BMad, Claude, OpenCode, and other AI agent tools and workflows.
7.3 KiB
Troubleshooting Guide
This guide covers common issues when deploying Astro 6 to Cloudflare Workers.
Table of Contents
Build Errors
"MessageChannel is not defined"
Symptoms:
- Build fails with reference to
MessageChannel - Occurs when using React 19 with Cloudflare adapter
Cause:
React 19 uses MessageChannel which is not available in the Cloudflare Workers runtime by default.
Solutions:
-
Add compatibility flag in
wrangler.jsonc:{ "compatibility_flags": ["nodejs_compat"] } -
Use React 18 temporarily if the issue persists:
npm install react@18 react-dom@18 -
Check for related GitHub issues:
"Cannot find module '@astrojs/cloudflare'"
Symptoms:
- Import error in
astro.config.mjs - Type errors in TypeScript
Solutions:
-
Install the adapter:
npm install @astrojs/cloudflare -
Verify installation:
npm list @astrojs/cloudflare -
For Astro 6, ensure v13+:
npm install @astrojs/cloudflare@beta
"Too many files for webpack"
Symptoms:
- Build fails with file limit error
- Occurs in large projects
Solution:
The Cloudflare adapter uses Vite, not webpack. If you see this error, check:
-
Ensure adapter is properly configured:
// astro.config.mjs import cloudflare from '@astrojs/cloudflare'; export default defineConfig({ adapter: cloudflare(), }); -
Check for legacy configuration:
- Remove any
@astrojs/vercelor other adapter references - Ensure
outputmode is set correctly
- Remove any
Runtime Errors
404 Errors on Specific Routes
Symptoms:
- Some routes return 404 after deployment
- Static assets not found
Solutions:
-
Check
_routes.jsonconfiguration (for advanced routing):{ "version": 1, "include": ["/*"], "exclude": ["/api/*"] } -
Verify build output:
npm run build ls -la dist/ -
Check wrangler.jsonc assets directory:
{ "assets": { "directory": "./dist", "binding": "ASSETS" } }
"env is not defined" or "runtime is not defined"
Symptoms:
- Cannot access Cloudflare bindings in Astro code
- Runtime errors in server components
Solutions:
-
Ensure TypeScript types are configured:
// src/env.d.ts type Runtime = import('@astrojs/cloudflare').Runtime<Env>; declare namespace App { interface Locals extends Runtime {} } -
Access bindings correctly:
--- // Correct const env = Astro.locals.runtime.env; const kv = env.MY_KV_NAMESPACE; // Incorrect const kv = Astro.locals.env.MY_KV_NAMESPACE; --- -
Verify platformProxy is enabled:
// astro.config.mjs adapter: cloudflare({ platformProxy: { enabled: true, }, })
Deployment Issues
"Authentication required" or "Not logged in"
Symptoms:
wrangler deployfails with authentication error- CI/CD deployment fails
Solutions:
-
Authenticate locally:
npx wrangler login -
For CI/CD, create API token:
- Go to Cloudflare Dashboard → My Profile → API Tokens
- Create token with "Edit Cloudflare Workers" template
- Set as
CLOUDFLARE_API_TOKENin GitHub/GitLab secrets
-
Set account ID:
# Get account ID npx wrangler whoami # Add to wrangler.jsonc or environment export CLOUDFLARE_ACCOUNT_ID=your-account-id
"Project name already exists"
Symptoms:
- Deployment fails due to naming conflict
Solutions:
-
Change project name in wrangler.jsonc:
{ "name": "my-app-production" } -
Or use environments:
{ "env": { "staging": { "name": "my-app-staging" } } }
Deployment succeeds but site doesn't update
Symptoms:
wrangler deployreports success- Old version still served
Solutions:
-
Clear browser cache (Ctrl+Shift+R or Cmd+Shift+R)
-
Verify deployment:
npx wrangler deployments list -
Check for cached versions:
npx wrangler versions list -
Force deployment:
npx wrangler deploy --compatibility-date 2025-01-19
Performance Issues
Slow initial page load
Symptoms:
- First Contentful Paint (FCP) > 2 seconds
- Large Time to First Byte (TTFB)
Solutions:
-
Use hybrid or static output:
// Pre-render static pages where possible export const prerender = true; -
Enable image optimization:
adapter: cloudflare({ imageService: 'compile', }) -
Cache at edge:
export async function getStaticPaths() { return [{ params: { id: '1' }, props: { data: await fetchData() }, }]; }
High cold start latency
Symptoms:
- First request after inactivity is slow
- Subsequent requests are fast
Solutions:
-
Use mode: 'directory' for better caching:
adapter: cloudflare({ mode: 'directory', }) -
Keep bundle size small - avoid heavy dependencies
-
Use Cloudflare KV for frequently accessed data:
const cached = await env.KV.get('key'); if (!cached) { const data = await fetch(); await env.KV.put('key', data, { expirationTtl: 3600 }); }
Development Server Issues
Styling not applied in dev mode (Astro 6 Beta)
Symptoms:
- CSS not loading in
astro dev - Works in production but not locally
Status: Known bug in Astro 6 beta
Workarounds:
-
Use production build locally:
npm run build npx wrangler dev --local -
Check GitHub issue for updates:
Cannot test bindings locally
Symptoms:
Astro.locals.runtime.envis undefined locally- Cloudflare bindings don't work in dev
Solutions:
-
Ensure platformProxy is enabled:
adapter: cloudflare({ platformProxy: { enabled: true, configPath: './wrangler.jsonc', }, }) -
Create .dev.vars for local secrets:
API_KEY=local_key DATABASE_URL=postgresql://localhost:5432/db -
Use remote development:
npx wrangler dev --remote
Getting Help
If issues persist:
-
Check official documentation:
-
Search existing issues:
-
Join community: