This error occurs because the dependencies haven't been installed yet. Follow these steps:
bun installThis may take 2-5 minutes as it installs all dependencies including:
- Next.js and React
- Cloudflare packages
- Database and ORM packages
- Image processing libraries (Sharp)
- Development tools
Check that the package is installed:
ls node_modules/@opennextjs/cloudflareYou should see the package directory.
Now you can build:
bun run buildThis runs: bunx opennextjs-cloudflare which:
- Builds your Next.js app
- Transforms it for Cloudflare Workers
- Creates the
.open-nextdirectory
If bunx doesn't work, try:
npx opennextjs-cloudflare# Clear cache and try again
rm -rf node_modules bun.lockb
bun install# Clean build artifacts
rm -rf .next .open-next
# Try building again
bun run buildSharp (image processing) can sometimes have issues on macOS:
# If Sharp fails to install, try:
bun add sharp --force
# Or use npm for Sharp specifically:
npm install sharpWhen build succeeds, you should see:
✓ Creating an optimized production build
✓ Compiled successfully
✓ Linting and checking validity of types
✓ Collecting page data
✓ Generating static pages
✓ Finalizing page optimization
Route (app) Size
┌ ○ / X kB
└ ○ /api/trpc/[trpc] X kB
○ (Static) prerendered as static content
✓ OpenNext build complete!
After successful build:
-
Test locally with Wrangler:
bun run cf:dev
-
Deploy to Cloudflare:
bun run deploy
-
View your site: The deployment URL will be shown in the output
- Run
bun install - Create
.env.localfrom.env.example - Update environment variables
- Create Cloudflare D1 database
- Create Cloudflare R2 bucket
- Create Cloudflare KV namespace
- Update wrangler.jsonc with IDs
- Run
bun run db:generate - Run
bun run db:migrate:dev - Run
bun run db:seed(optional) - Run
bun run build - Run
bun run devfor local development
- Check QUICKSTART.md for quick setup
- Read docs/SETUP.md for detailed instructions
- See README.md for full documentation
Solution: Dependencies not installed. Run bun install.
Solution: Create D1 database and update wrangler.jsonc.
Solution: Create R2 bucket and update wrangler.jsonc.
Solution: Check .env.local and ensure all required variables are set.
Pro Tip: Use the automated setup script:
chmod +x scripts/setup.sh
./scripts/setup.shThis handles most of the setup automatically!