Bun v0.8.0 | Bun Weblog

Bun v0.8.0 provides debugger help, implements fetch streaming, and unblocks SvelteKit. ReadStream and WriteStream from node:tty
are applied, and .setRawMode()
now works on course of.stdin
, unblocking a number of interactive CLI instruments. Plus Node.js compatibility updates, bug fixes, stability enhancements.
Bun 1.0 is approaching September seventh! Register for the launch stream at https://bun.sh/1.0.
Bun is an extremely quick JavaScript runtime, bundler, transpiler, and bundle supervisor — multi function. We have been releasing quite a lot of modifications to Bun lately. This is a recap of the previous few releases. In case you missed it:
v0.7.0
– Net Employees,--smol
,structuredClone()
, WebSocket reliability enhancements,node:tls
fixes, and extra.v0.7.1
– ES Modules load 30-250% quicker,fs.watch
fixes, and manynode:fs
compatibility enhancements.v0.7.2
– Implementsnode:worker_threads
,node:diagnostics_channel
, andBroadcastChannel
.v0.7.3
– Protection reporting inbun take a look at
, plus take a look at filtering withbun take a look at -t
.
To put in Bun:
curl
curl -fsSL https://bun.sh/set up | bash
docker
docker run --rm --init --ulimit memlock=-1:-1 oven/bun
To improve Bun:
Bun now implements debugger help through WebKit’s Inspector Protocol. To make use of it, run your file or script with the --inspect
flag. Take into account the next easy HTTP server.
server.ts
const server = Bun.serve({
fetch(req){
console.log(req.url);
return new Response("Good day world!");
}
});
console.log(`Listening on http://localhost:${server.port}`);
After we run this file with --inspect
, it begins our HTTP server and spins up a localhost WebSocket server on an unused port. This WebSocket server makes use of the Inspector Protocol to speak with debugging instruments, which may introspect and management the operating bun
course of.
Listening on http://localhost:3000
------------------ Bun Inspector ------------------
Listening at:
ws://localhost:6499/0tqxs9exrgrm
Examine in browser:
https://debug.bun.sh/#localhost:6499/0tqxs9exrgrm
------------------ Bun Inspector ------------------
Using debug.bun.sh
The --inspect
flag may even print a https://debug.bun.sh#
URL to the console. This area debug.bun.sh
hosts a stripped-down model of Safari Developer Instruments designed for debugging Bun. Open the hyperlink in your most popular browser and a brand new debugging session will begin mechanically.

From the net debugger, you’ll be able to examine the at the moment operating code and set breakpoints. As soon as a breakpoint is triggered, you’ll be able to:
- View all variables in scope
- Execute code within the console, with full entry to in-scope variables and Bun APIs
- Step by means of your code step-by-step

Learn the Debug Bun with the web debugger information for extra full documentation.
The brand new bun replace
command will replace all venture dependencies to the most recent variations which can be appropriate with the semver ranges in your bundle.json
.
To replace a selected dependency:
Word — In contrast to npm
, the bun improve
command is reserved for upgrading Bun itself. It’s not an alias for bun replace
.
Because of @alexlamsl for implementing this function.
Improved help for environment variables in Worker
has unblocked SvelteKit. Scaffold your venture with create-svelte
.
bunx create-svelte my-app
create-svelte model 5.0.5
┌ Welcome to SvelteKit!
│
◇ Which Svelte app template?
│ SvelteKit demo app
│
◇ Add kind checking with TypeScript?
│ Sure, utilizing TypeScript syntax
│
◇ Choose further choices (use arrow keys/area bar)
│ none
│
└ Your venture is prepared!
✔ Typescript
Inside Svelte parts, use <script lang="ts">
Set up community-maintained integrations:
https://github.com/svelte-add/svelte-add
To put in dependencies and begin the dev server:
Open localhost:3000
to see the demo SvelteKit app in motion.

With improved node:tty
and node:fs
help, the Nuxt growth server now works with the Bun runtime. To get began, use the nuxi
command-line instrument.
bunx --bun nuxi init my-app
As soon as dependencies are put in, begin the event server with the "dev"
bundle.json script.
$ nuxt dev
Nuxt 3.6.5 with Nitro 2.5.2
> Native: http://localhost:3000/
> Community: http://192.168.0.21:3000/
> Community: http://[fd8a:d31d:481c:4883:1c64:3d90:9f83:d8a2]:3000/
✔ Nuxt DevTools is enabled v0.8.0 (experimental)
ℹ Vite shopper warmed up in 547ms
✔ Nitro inbuilt 244 ms
The --bun
flag ensures the server is utilizing the Bun runtime as an alternative of Node.js. By default the nuxt
CLI makes use of Node.js.
Then go to http://localhost:3000 to see the default Nuxt welcome display.

Word — There are nonetheless some points with Nuxt’s construct
command. When doing a manufacturing construct, use bun run construct
as an alternative of bun --bun run construct
. This can use Node.js to run Nuxt’s construct pipeline. Observe this problem here.
Confer with the Building an app with Nuxt and Bun for a extra full walkthrough.
Bun now implements fetch()
response physique streaming, due to @cirospaciari. This implies you could now stream information from a fetch response, as an alternative of ready for the complete response to be downloaded.
const res = await fetch("https://instance.com/bigfile.txt");
// learn the response chunk-by-chunk!
for await (const chunk of res.physique) {
console.log(chunk);
}
Use OpenAI in Bun
Streaming is very helpful when working with APIs that take awhile to reply. Now you’ll be able to stream responses from OpenAI’s API in Bun.
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: "my api key",
});
const stream = await openai.chat.completions.create({
mannequin: "gpt-4",
messages: [{ role: "user", content: "Say this is a test" }],
stream: true,
});
for await (const half of stream) "");
Beforehand, the next would buffer the response physique, which means it will solely ship the response as soon as the complete physique had been generated.
import { serve, sleep } from "bun";
serve({
fetch(req) {
return new Response(
new ReadableStream({
async pull(controller) {
for (let i = 0; i < 20; i++) {
controller.enqueue("Good day world!");
await sleep(42);
}
controller.shut();
},
}),
);
},
});
// Good day World!Good day World!Good day World!...[~840ms]
That is not what folks need! Now, the response physique is streamed, which means it is despatched to the shopper because it’s generated.
import { serve, sleep } from "bun";
serve({
fetch(req) {
return new Response(
new ReadableStream({
async pull(controller) {
for (let i = 0; i < 20; i++) {
controller.enqueue("Good day world!");
await sleep(42);
}
controller.shut();
},
}),
);
},
});
// Good day world! [42ms]
// Good day world! [42ms]
// Good day world! [42ms]
Beforehand, streaming was solely supported when utilizing ReadableStream with kind: "direct"
, a Bun-specific quick path for streaming.
import { serve, sleep } from "bun";
serve({
port: 3000,
fetch(req) {
return new Response(
new ReadableStream({
// bun particular choice
kind: "direct",
async pull(controller) {
for (let i = 0; i < 20; i++) {
controller.write("Good day world!");
// in bun < 0.8.0, flush() was required
controller.flush();
// now bun will mechanically flush pending writes as soon as the microtask queue is drained
await sleep(42);
}
controller.finish();
},
}),
);
},
});
// Good day world! [42ms]
// Good day world! [42ms]
// Good day world! [42ms]
// Good day world! [42ms]
We nonetheless have optimization work forward to make streaming utilizing the default ReadableStream kind quick. For now, we advocate utilizing kind: "direct"
to get the quickest attainable streaming.

The ReadStream
and WriteStream
courses from node:tty
have been applied, and course of.stdin
is now an occasion of ReadStream
. Accordingly, it is now attainable to allow “uncooked mode” on course of.stdin
.
course of.stdin.setRawMode(true);
Support for inquirer
and other prompt libraries
This makes it attainable to learn keypresses with out ready for a newline character, which is essential for interactive CLI instruments. The favored libraries inquirer
, enquirer
, and prompts
are actually totally supported.
Run the next command to interactively scaffold a Remix app utilizing Bun and the interactive create-remix
command-line instrument.
Because of @dylan-conway for implementing this function.
test.each
and describe.each
Because of @jecquas, Bun now helps take a look at.every
and describe.every
from Jest. This makes it simple to run the identical take a look at with completely different inputs.
describe.every([
[1, 1, 2],
[1, 2, 3],
[2, 1, 3],
])("add(%i, %i)", (a, b, anticipated) => {
take a look at(`returns ${anticipated}`, () => {
count on(a + b).toBe(anticipated);
});
});
.toSatisfy()
and .toIncludeRepeated()
Because of @TiranexDev, bun take a look at
now helps additional matchers. These matchers are a part of jest-extended
and are actually natively supported by bun take a look at
.
Pattern utilization of .toSatisfy()
:
const isOdd = (worth: quantity) => worth % 2 !== 0;
it("toSatisfy", () => {
count on(1).toSatisfy(isOdd);
count on(2).not.toSatisfy(isOdd);
});
Pattern utilization of .toIncludeRepeated()
:
take a look at("toIncludeRepeated", () => {
// verify if string incorporates substring precisely 2 instances
count on("howdy howdy").toIncludeRepeated("howdy", 2);
// works with .not
count on("howdy howdy world").not.toIncludeRepeated("howdy", 1);
});
The Node.js Buffer.toString("hex")
perform will get optimized with SIMD, resulting in 40x quicker efficiency.
Objects can now be augmented with customized formatters utilizing the Bun.examine.customized
image. For compatibility causes, util.examine.customized
from Node.js’s node:util
works too.
class Password {
worth: string;
constructor(worth: string) {
this.worth = worth;
}
[Bun.inspect.custom]() {
return "Password <********>";
}
}
const p = new Password("secret");
console.log(p);
// => "Password <********>"
The File
constructor has been added as a brand new international. File
situations will be constructed.
const file = new File(["hello world"], "howdy.txt", {
kind: "textual content/plain",
lastModified: Date.now() - 1000,
});
file.dimension; // 11
file.title; // "howdy.txt"
file.kind; // "textual content/plain"
file.lastModified; // 1693597759310573
Accordingly,
A JIT crash in Buffer
-related capabilities has been mounted. This crash was brought on by incorrect unwanted effects when handed to DOMJIT which led to a crash throughout kind validation when the capabilities have been known as. This impacted a number of libraries and the crash started after a JavaScriptCore improve in Bun v0.7.3.
This crash would trigger EXC_BREAKPOINT
to be thrown after sufficient calls to Buffer.alloc
, Buffer.allocUnsafe
, Buffer.isBuffer
have been known as.
Buffer.toString(“hex”) reminiscence leak repair
A reminiscence leak has been fixed within the implementation of buffer.toString("hex")
.
NAPI fixes and help for resvg
, sharp
A pair bugs within the NAPIClass
constructor and napi_create_external_arraybuffer
/napi_create_external_buffer
have been mounted. The resolves points when utilizing resvg-js
or sharp
.
Higher error when this
is invalid
When calling a technique with an sudden worth for this
, Bun now reports an informative error.
const { json } = new Response(`"howdy"`);
json();
// ^ TypeError: Anticipated `this` to be instanceof Response
Deal with cross-device file copies
Bun now detects when a file copying operation (e.g fs.copyFile
) is making an attempt to repeat recordsdata throughout units or partitions and falls again to a handbook file copy syscall.
Repair Bun.deepEqual
URL comparability
#4105
fixes a bug the place URLs we’re not correctly in contrast by their inside href
.
10% Regression in async-await efficiency on macOS has been mounted
- The daylight financial savings time cache is now not up to date on every microtask name. This regression started in v0.7.x.
A number of fixes to streams
#4251
contains quite a lot of enhancements and bugfixes within the implementation of ReadableStream
have been mounted. This contains:
- Pending writes to HTTP response our bodies are mechanically flushed as soon as the microtask queue has been drained, fixing #1886
- Improved error dealing with inside
pull
.
As Bun 1.0 approaches, we have been monitoring down remaining reminiscence leaks and crashes.
#4028 |
[install] Deal with bun add of present peerDependencies accurately by @alexlamsl |
#4026 |
Operating lacking scripts exits with non-0 by @YashoSharma |
#4030 |
Bind require.resolve`() by @Jarred-Sumner |
#4034 |
Normalize Request URLs by @Jarred-Sumner |
#4042 |
Repair path.normalize edge case. by @Hanaasagi |
#4043 |
Compile Bun’s transpiler to WASM and add take a look at analyzer by @Jarred-Sumner |
#4048 |
Repair iterating headers with set-cookie by @dylan-conway |
#4000 |
implement fetching information urls by @dylan-conway |
#4054 |
Repair Bun.hash capabilities by @jhmaster2000 |
#4064 |
Repair path.format compatibility problem. by @Hanaasagi |
#4073 |
Repair require(“console”) #3820 by @paperdave |
#4076 |
Set exports to {} in user-constructed CommonJSModuleRecords by @paperdave |
#4086 |
Repair XLSX.learn coredump by @Hanaasagi |
#4027 |
Add help for bun –revision by @YashoSharma |
#4106 |
Repair segfault in base64url encoder #4062 by @Jarred-Sumner |
#4109 |
Deal with thundering herd of setInterval by @Jarred-Sumner |
#4111 |
Repair reminiscence leak in Buffer.toString(‘base64url’) by @Jarred-Sumner |
#4113 |
Run recordsdata with out extensions by @dylan-conway |
#4117 |
Make astro construct barely quicker |
#4125 |
Assist TypeScript’s export kind * as Foo from 'bar' by @Jarred-Sumner |
#4126 |
bun-wasm fixes & enhancements by @jhmaster2000 |
#4131 |
Deprecate loading node_modules.bun by @Jarred-Sumner |
#4129 |
Repair customized config path not working. by @Hanaasagi |
#4114 |
Repair employee occasion loop ref/unref + leak by @paperdave |
#4152 |
Make builtins’ supply origin use a legitimate url by @paperdave |
#4155 |
Repair importing too lengthy of strings by @paperdave |
#4162 |
Repair methodology title typo by @Hanaasagi |
#4157 |
Repair occasion loop problem with Bun.join by @paperdave |
#4172 |
Replace docs our present standing of node compatibility by @paperdave in https://github.com/oven-sh/bun/pull/4172 |
#4173 |
Create domjit.take a look at.ts by @dylan-conway in https://github.com/oven-sh/bun/pull/4173 |
#4150 |
Repair prisma linux era by @cirospaciari in https://github.com/oven-sh/bun/pull/4150 |
#4181 |
Repair leaking .ptr by @Jarred-Sumner in https://github.com/oven-sh/bun/pull/4181 |
#4192 |
right information’s bunfig instance choice by @xxxhussein in https://github.com/oven-sh/bun/pull/4192 |
#4193 |
refactor: transfer HTMLRewriter to c++ bindings by @bru02 in https://github.com/oven-sh/bun/pull/4193 |
#4191 |
Repair(node:fs): add buffer parameter in fs.learn callback. by @Hanaasagi in https://github.com/oven-sh/bun/pull/4191 |
#4154 |
Permit IncomingRequest.req to be overwritten. by @paperdave in https://github.com/oven-sh/bun/pull/4154 |
#4098 |
Assist Nitro by @paperdave in https://github.com/oven-sh/bun/pull/4098 |
#4194 |
Add util.examine.customized help to util.examine/Bun.examine/console.log by @paperdave in https://github.com/oven-sh/bun/pull/4194 |
#4187 |
Take away most C API usages, add debugger fairly printers for Headers , URLSearchParams , FormData , Employee , EventTarget by @Jarred-Sumner in https://github.com/oven-sh/bun/pull/4187 |
#4208 |
Implement BigIntStats by @paperdave in https://github.com/oven-sh/bun/pull/4208 |
#4206 |
feat: add self-closing & can-have-content by @bru02 in https://github.com/oven-sh/bun/pull/4206 |
#4213 |
Add inline sourcemaps when --inspect is enabled by @Jarred-Sumner in https://github.com/oven-sh/bun/pull/4213 |
#4220 |
Fixes #172 by @Jarred-Sumner in https://github.com/oven-sh/bun/pull/4220 |
#4221 |
Repair crash impacting sharp & resvg by @Jarred-Sumner in https://github.com/oven-sh/bun/pull/4221 |
#4210 |
Add unsupported (but) remark to distroless picture by @o-az in https://github.com/oven-sh/bun/pull/4210 |
#4163 |
Repair(bundler): use completely different alias mappings based mostly on the goal. by @Hanaasagi in https://github.com/oven-sh/bun/pull/4163 |
#4231 |
Repair take a look at failures from 3a9a6c63a by @Jarred-Sumner in https://github.com/oven-sh/bun/pull/4231 |
#4222 |
Implement --inspect-brk by @Jarred-Sumner in https://github.com/oven-sh/bun/pull/4222 |
#4230 |
Fixes #1675 by @Jarred-Sumner in https://github.com/oven-sh/bun/pull/4230 |
#4235 |
Repair reminiscence leak in buffer.toString("hex") by @Jarred-Sumner in https://github.com/oven-sh/bun/pull/4235 |
#4237 |
Buffer.toString(‘hex’) will get 40x quicker by @Jarred-Sumner in https://github.com/oven-sh/bun/pull/4237 |
#4243 |
feat: Implement Bun.examine.customized by @paperdave |
#4156 |
Implement napi_ref_threadsafe_function by @paperdave |
#4242 |
Repair crypto.EC constructor by @paperdave |
#4226 |
Repair(bundler): enable producing exe file in nested path. by @Hanaasagi |
#4245 |
Repair emitKeyPresses with backspace + quote by @paperdave |
#4127 |
fetch(stream) add stream help for compressed and uncompressed information by @cirospaciari |
#4244 |
import errors have code set to ERR_MODULE_NOT_FOUND and require errors have code set to MODULE_NOT_FOUND by @Jarred-Sumner |
#4250 |
repair stdin stream unref and resuming by @dylan-conway |
#4247 |
repair fsevents and stub for qwikcity by @paperdave |
#4264 |
repair(parser): yield earlier than ] should not be a syntax error by @paperdave |
#4256 |
Ask for bun --revision as an alternative bun -v in PR template by @xHyroM |
#4273 |
Repair extra sorts. by @xxxhussein |
#4251 |
Bunch of streams fixes by @Jarred-Sumner |