{"id":27627,"library":"bunflare","title":"Bunflare","description":"Bunflare v0.2.25 is a Bun bundler plugin that transforms Bun-native APIs (e.g., Bun.serve, bun:sqlite, Bun.password.hash) into Cloudflare Workers equivalents at build time. It targets developers who want Bun's DX but need to deploy to Cloudflare Workers. Key differentiators: zero runtime overhead (transform happens at build time), no code changes required for the developer, supports auto-discovery from wrangler.jsonc, and covers a wide range of Bun APIs including D1, KV, R2, Hyperdrive, WebCrypto, Workers Assets, and fullstack builds. Released as a dev dependency, it requires Bun >=1.0.0 and optionally integrates with Hono and Drizzle ORM. The package ships with TypeScript types. The project is actively maintained with recent commits.","status":"active","version":"0.2.25","language":"javascript","source_language":"en","source_url":"https://github.com/fhorray/bunflare","tags":["javascript","bun","cloudflare","workers","hono","fullstack","bundler","plugin","d1","typescript"],"install":[{"cmd":"npm install bunflare","lang":"bash","label":"npm"},{"cmd":"yarn add bunflare","lang":"bash","label":"yarn"},{"cmd":"pnpm add bunflare","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for fullstack/SPA builds using Hono routes converted to Cloudflare Workers fetch handlers","package":"hono","optional":true},{"reason":"Required for D1 SQL integration when using Drizzle ORM with the SQLite shim","package":"drizzle-orm","optional":true}],"imports":[{"note":"BunflareConfig is a TypeScript type, imported with 'import type' to avoid runtime errors.","wrong":"import { BunflareConfig } from 'bunflare' // BunflareConfig is a type, not a value","symbol":"default (BunflareConfig type)","correct":"import type { BunflareConfig } from 'bunflare'"},{"note":"The package is ESM-only. Use import statement.","wrong":"const bunflare = require('bunflare') // Bunflare is ESM-only, require() fails","symbol":"default (plugin)","correct":"import bunflare from 'bunflare'"},{"note":"CloudflareBindings is a global interface you declare yourself, often populated by 'wrangler types' generation.","wrong":"import { CloudflareBindings } from 'bunflare' // CloudflareBindings is not exported from bunflare","symbol":"CloudflareBindings (interface)","correct":"interface CloudflareBindings { } // augmented by 'wrangler types' into worker-configuration.d.ts"}],"quickstart":{"code":"// Install: bun add -d bunflare\n\n// bunflare.config.ts\nimport type { BunflareConfig } from 'bunflare';\n\nexport default {\n  entrypoint: './index.ts',\n  // Optional: bindings are auto-discovered from wrangler.jsonc\n  // sqlite: { binding: 'DB' },\n} satisfies BunflareConfig;\n\n// index.ts (source code, unchanged)\nBun.serve({\n  port: 3000,\n  fetch(request) {\n    return new Response('Hello from Bun!');\n  },\n});\n\n// Build command:\n// bun bunflare\n// Outputs Cloudflare Worker-compatible bundle to dist/worker.js","lang":"typescript","description":"Shows minimal setup: install as devDep, create config with entrypoint, write standard Bun code, build with `bun bunflare`."},"warnings":[{"fix":"Upgrade Bun to >=1.0.0 and bunflare to latest.","message":"Bunflare v0.2.x requires Bun >=1.0.0. Older Bun versions may produce errors or fail to load the plugin.","severity":"breaking","affected_versions":"<0.2.0"},{"fix":"Avoid TLS/unix socket options in Bun.serve. Use regular HTTP/HTTPS or omit options.","message":"Bunflare transforms Bun.serve into Cloudflare Workers fetch handler. If your Bun.serve uses advanced features (e.g., TLS options, unix sockets), those will not work on Workers and build may fail.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Use `bun bunflare` (if using Bun) or add a script in package.json: \"build\": \"bun bunflare\".","message":"The `bunflare` CLI command is being phased out in favor of `bun bunflare`. Running `npx bunflare` may produce deprecation warnings.","severity":"deprecated","affected_versions":">=0.2.0"},{"fix":"Ensure wrangler.jsonc exists with correct binding names. Use explicit config in bunflare.config.ts if needed.","message":"Bunflare automatically discovers bindings from wrangler.jsonc. If the file is missing or misconfigured, bindings (D1, KV, R2) will not work at runtime on Workers.","severity":"gotcha","affected_versions":">=0.2.0"},{"fix":"Create global.d.ts with the snippet from the readme and run 'wrangler types' to generate worker-configuration.d.ts.","message":"TypeScript type augmentation for Bun.env requires a manual global.d.ts and running 'wrangler types'. Without it, TypeScript errors appear on Bun.env.KEY usage.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Install drizzle-orm: bun add drizzle-orm","message":"Using bun:sqlite with Drizzle ORM requires drizzle-orm as peer dependency. Not installing it will cause runtime errors when SQL queries are executed via Drizzle on D1.","severity":"gotcha","affected_versions":">=0.2.0"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Ensure your build step uses 'bun bunflare' or the Bunflare plugin, and deploy the output bundle (not the source).","cause":"Trying to run Bun-specific code in a Cloudflare Workers environment without building with Bunflare.","error":"ReferenceError: Bun is not defined"},{"fix":"Run 'bun add -d bunflare' and ensure your tsconfig includes node_modules/@types or the package types.","cause":"Bunflare not installed or missing in tsconfig's 'types' or 'includes'.","error":"Cannot find module 'bunflare' or its corresponding type declarations."},{"fix":"Switch to ESM (use import statements) or use a dynamic import: const bunflare = await import('bunflare')","cause":"Attempting to require() an ESM-only package with CommonJS require() in Node.js.","error":"SyntaxError: Unexpected token 'export'"},{"fix":"Verify the binding name in wrangler.jsonc and your config match. Also check that the D1 database is created and bound in Cloudflare dashboard.","cause":"Cloudflare Worker doesn't have a D1 binding named 'DB', or the binding name in bunflare.config.ts doesn't match the deployed binding.","error":"Binding 'DB' not found in environment"},{"fix":"Use import type { BunflareConfig } from 'bunflare' consistently and avoid re-exporting from other files.","cause":"Type conflict when importing BunflareConfig from both bunflare and another module that re-exports it.","error":"Type 'BunflareConfig' is not assignable to type 'BunflareConfig' (different namespaces)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}