Astro SSR with Bun
Bun brings a ton of interesting new APIs to the table, and since migrating my blog to use Bun as a build runtime and package manager, I’ve experimented a little with Bun in server-side rendering. Here’s a quick post on how to setup an Astro project with Bun on the server.
While Bun does support Astro, there are known issues both in dev and in production. Issues should be reported to the Bun project. I don’t recommend using this beyond experimentation & fun projects for the time being.
Bun advertises Node API compatibility, which allows us to take advantage of the existing Node adapter.
You can then run the dev server with the following:
And build it with:
To run the built server, call the entrypoint:
Bun exposes types via the
bun-types package. Install the package
And add it to your
Using the runtime
You can now use the Bun runtime in your pages (and take advantage of the typed intellisense). For example, you can reference
Bun.version to get the current installed version of Bun.
You can find my template for Astro + Bun SSR on Github.
A Recipe For Buns
I’ve written a more complete recipe on using Bun with Astro projects, which you can find in the official Astro docs.