Astro + Cloudflare Pages + Bun is a great combination for building and deploying static websites. But recently, you might have faced some issues with builds failing with your Astro site on Cloudflare Pages using Bun.
/opt/buildhome/repo/node_modules/string-width/index.js
[ERR_REQUIRE_ESM]: require() of ES Module /opt/buildhome/repo/node_modules/strip-ansi/index.js from /opt/buildhome/repo/node_modules/string-width/index.js not supported.
This is due to the fact that Cloudflare Pages has not yet updated the latest Bun version. To make it work, all you need to do is to simply add an environment variable to your Cloudflare Pages project.
Environment variable:
Key: BUN_VERSION
Value: 1.1.29
This will force Cloudflare Pages to use Bun 1.1.29 instead of the latest version.
This is a temporary solution until Cloudflare Pages updates the Bun version.