Bun v0.4

Ashcon Partovi · December 23, 2022

We're hiring C/C++ and Zig engineers to build the future of JavaScript!

Happy Holidays! We're excited to release Bun v0.4.0 with support for more Node.js APIs, increased stability, lots of bug fixes, and a new command: bunx.

Introducing bunx

This version introduces bunx, Bun's equivalent of npx with 100x faster startup times. It runs executables from local or remote npm packages.

$ bunx esbuild --version

As with npx, it will check for a locally installed package first, then fall back to auto-installing from npm into a shared global cache. With Bun's fast startup times, it's roughly 100x faster than npx for locally installed packages.

The --bun flag

By default, Bun respects the #!/usr/bin/env node shebang at the top of scripts or executables that are run with bun run <script> or bunx <command>.

// foo.js
#! /usr/bin/env node

$ bun run foo.js

To override this behavior, pass the --bun flag. This temporarily aliases node to bun for the duration of the execution.

$ bun --bun run foo.js

In the future, we might make this behaviour the default once Bun's Node.js compatibility is more complete.

bun --bun vite

Node.js compatibility

Support for Node.js APIs continues to be a top priority for Bun. As of Bun v0.4.0, you can now use the following APIs:

Setup and teardown in bun:test

Bun has a built-in test runner that you can run using the command: bun wiptest. You can now define Jest-style lifecycle hooks for the setup and teardown of tests.

import { beforeAll, test } from "bun:test";

let tests;
beforeAll(async () => {
  const response = await fetch("https://example.com/path/to/resource");
  tests = await response.json();

test("that integration tests are defined", () => {

Bun.deepEquals() strict

You can now pass a strict argument to Bun.deepEquals(), which will have the same behaviour as expect().toStrictEqual().

const a = { entries: [1, 2] };
const b = { entries: [1, 2], extra: undefined };

Bun.deepEquals(a, b); // => true
Bun.deepEquals(a, b, true); // => false

bun pm

In case you missed it, Bun has a command that allows you see information about your packages and lockfile in a project: bun pm.

Output of "bun pm"

bun pm ls

In Bun v0.4.0 there is new sub-command, bun pm ls, which will list all the packages and versions in your project, similar to npm ls.

Output of "bun pm ls"

Notable Fixes

PR log


We'd also like to thank everyone who helped contribute to Bun.