Skip to content

secondsky/claude-skills / plugins/cloudflare-nextjs/skills/cloudflare-nextjs

cloudflare-nextjs

Verified

Deploy Next.js to Cloudflare Workers via the OpenNext adapter (@opennextjs/cloudflare). Use for SSR/ISR/SSG/App or Pages Router, getCloudflareContext, bindings (D1/R2/KV/AI/Hyperdrive), caching tiers, skew protection, multi-worker, custom worker, env vars, or worker size/runtime/keep_names/FinalizationRegistry/connection-scoping errors.

scripts/analyze-bundle.sh

View on GitHub
#!/bin/bash
# Analyze Next.js Worker bundle size to debug worker size limit errors

set -e

echo "πŸ“Š Analyzing Worker bundle size..."
echo ""

# Check if we're in a Next.js project
if [ ! -f "package.json" ]; then
    echo "❌ Error: No package.json found. Run this script from your Next.js project root."
    exit 1
fi

# Check if @opennextjs/cloudflare is installed
if ! grep -q "@opennextjs/cloudflare" package.json; then
    echo "❌ Error: @opennextjs/cloudflare is not installed."
    echo "Run: npm install --save-dev @opennextjs/cloudflare"
    exit 1
fi

# Build the project
echo "πŸ”¨ Building Next.js project with OpenNext adapter..."
npx opennextjs-cloudflare build

# Check if build succeeded
if [ ! -d ".open-next" ]; then
    echo "❌ Error: Build failed - .open-next directory not found"
    exit 1
fi

# Navigate to build output
cd .open-next/server-functions/default

echo ""
echo "βœ… Build complete!"
echo ""
echo "πŸ“ Build output location:"
echo "   .open-next/server-functions/default/"
echo ""

# Check if handler exists
if [ ! -f "handler.mjs" ]; then
    echo "❌ Error: handler.mjs not found in build output"
    exit 1
fi

# Get file sizes
HANDLER_SIZE=$(stat -f%z "handler.mjs" 2>/dev/null || stat -c%s "handler.mjs" 2>/dev/null || echo "unknown")
HANDLER_SIZE_MB=$(echo "scale=2; $HANDLER_SIZE / 1048576" | bc 2>/dev/null || echo "unknown")

echo "πŸ“¦ Worker Bundle Size:"
echo "   handler.mjs: $HANDLER_SIZE bytes (~${HANDLER_SIZE_MB} MiB uncompressed)"
echo ""
echo "πŸ“ Cloudflare Worker Size Limits:"
echo "   Free plan:  3 MiB (gzip-compressed)"
echo "   Paid plan: 10 MiB (gzip-compressed)"
echo ""

# Check for bundle metadata
if [ -f "handler.mjs.meta.json" ]; then
    echo "πŸ“Š Bundle Metadata:"
    echo "   File: handler.mjs.meta.json"
    echo ""
    echo "To analyze bundle composition:"
    echo "  1. Open handler.mjs.meta.json in ESBuild Bundle Analyzer"
    echo "  2. Identify large dependencies"
    echo "  3. Consider:"
    echo "     - Removing unused dependencies"
    echo "     - Using dynamic imports for code splitting"
    echo "     - Externalizing large packages if possible"
    echo ""
else
    echo "⚠️  Bundle metadata (handler.mjs.meta.json) not found"
    echo ""
fi

# List all files in build output
echo "πŸ“‚ Build Output Contents:"
ls -lh
echo ""

# Check for common large dependencies
echo "πŸ” Checking for common large dependencies..."
if [ -f "handler.mjs" ]; then
    # Check for common problematic imports (this is a simple check)
    LARGE_DEPS=()

    if grep -q "prisma" handler.mjs 2>/dev/null; then
        LARGE_DEPS+=("@prisma/client")
    fi

    if grep -q "aws-sdk" handler.mjs 2>/dev/null; then
        LARGE_DEPS+=("aws-sdk")
    fi

    if grep -q "firebase" handler.mjs 2>/dev/null; then
        LARGE_DEPS+=("firebase")
    fi

    if grep -q "graphql" handler.mjs 2>/dev/null; then
        LARGE_DEPS+=("graphql")
    fi

    if [ ${#LARGE_DEPS[@]} -gt 0 ]; then
        echo "⚠️  Found potentially large dependencies:"
        for dep in "${LARGE_DEPS[@]}"; do
            echo "   - $dep"
        done
        echo ""
        echo "Consider:"
        echo "  - Using lighter alternatives"
        echo "  - Dynamic imports to reduce initial bundle"
        echo "  - Moving heavy operations to separate Workers"
        echo ""
    else
        echo "βœ… No obviously large dependencies detected"
        echo ""
    fi
fi

echo "πŸ’‘ Tips to Reduce Bundle Size:"
echo "  1. Remove unused dependencies from package.json"
echo "  2. Use dynamic imports: const module = await import('heavy-module')"
echo "  3. Split large features into separate routes/pages"
echo "  4. Check for duplicate dependencies (npm dedupe)"
echo "  5. Consider using lighter alternatives for heavy packages"
echo "  6. Review handler.mjs.meta.json for detailed breakdown"
echo ""
echo "πŸ“– More info:"
echo "   https://opennext.js.org/cloudflare/troubleshooting#worker-size-limits"
echo ""
writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 322kUpdated Claude CodeCodexVerifiedInstall
xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path β€” even casually (like "the xlsx in my downloads") β€” and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release.Stars: 118kUpdated Claude CodeCodexVerifiedInstall