Bun

Bun v1.0.3


Colin McDonnell · September 22, 2023

Bun v1.0.3 fixes numerous bugs, adds support for metadata reflection via TypeScript's emitDecoratorMetadata, improves fetch compatibility, unblocks private registries like Azure Artifacts and Artifactory, bunx bugfix, console.log() depth 8 -> 2, Node.js compatibility improvements, and more.

Thank you for reporting issues. We are working hard to fix them as quickly as possible.

Bun is an incredibly fast JavaScript runtime, bundler, transpiler, and package manager — all in one. We've been releasing a lot of changes to Bun recently. Here's a recap of the last few releases. In case you missed it:

  • v1.0.0 - Bun's first stable release!
  • v1.0.1 - Named imports for .json & .toml files, bugfixes to bun install, node:path, Buffer
  • v1.0.2 - Make --watch faster, plus bug fixes

To install Bun:

curl
npm
brew
docker
curl
curl -fsSL https://bun.sh/install | bash
npm
npm install -g bun
brew
brew tap oven-sh/bun
brew install bun
docker
docker pull oven/bun
docker run --rm --init --ulimit memlock=-1:-1 oven/bun

To upgrade Bun:

bun upgrade

emitDecoratorMetadata (used by Nest.js, TypeORM, and more)

Bun now supports metadata reflection via TypeScript's emitDecoratorMetadata. This means that you can use Nest.js with Bun, and it will work out of the box.

tsconfig.json
{
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true
  }
}

The emitDecoratorMetadata is a TypeScript compiler option that enables the generation of metadata for decorators via reflect-metadata.

Improved Nest.js support

The addition of emitDecoratorMetadata dramatically improves Nest.js support, as it relies on custom "Reflectors" to attach metadata and middleware to route handlers.

@Post()
@Roles(['admin']) // custom authentication decorator
async create(@Body() createCatDto: CreateCatDto) {
  this.catsService.create(createCatDto);
}

module.parent support

In Node, the CommonJS module.parent getter is a reference to the parent module that required the current module. This is useful for determining whether a module was run directly or required by another module.

if (module.parent) {
  // this module was required by another module
} else {
  // this module was run directly
}

Bun now supports module.parent in the same way that Node does.

For ES modules, you can use import.meta.main to find out if the current module started the Bun process.

Bugfixes for private npm registries

Improvements to fetch unblock the usage of bun install with popular private package registries like Azure Artifacts and JFrog Artifactory.

You can configure a private registry using bunfig.toml instead of .npmrc. Provide values for url, username, and password under the [install.registry] section of your bunfig.toml file.

bunfig.toml
[install.registry]
url = "https://pkgs.dev.azure.com/my-azure-artifacts-user/_packaging/my-azure-artifacts-user/npm/registry"
username = "my-azure-artifacts-user"
# Bun v1.0.3+ supports using an environment variable here
password = "$NPM_PASSWORD"

Alternatively, specify a token instead of a username and password. This is useful for Artifactory.

bunfig.toml
[install.registry]
url = "https://my-artifactory-server.com/artifactory/api/npm/npm-virtual"
token = "$NPM_TOKEN"

For more complete information, refer to our new guides:

[0.5ms] env message is now silent by default

Many people asked for this, so @colinhacks made it happen. The [0.5ms] env loaded message is now silent by default. You can still see it by setting logLevel to "debug" in bunfig.toml

Node.js compatiblity improvements

The work on Node.js compatibility continues. Here are some of the improvements in this release:

Implement console.Console constructor

The Node.js console.Console constructor has been implemented.

import { Console } from "console";
import { createWriteStream } from "fs";

const writer = new Console({ stdout: createWriteStream("log.txt") });

writer.log("hello");
writer.log("world", { x: 2 });

This fixes vitest and webpack's ts-loader when executed with the Bun runtime—though consider using bun test and bun build instead! Of course, there are a lot of tools and codebases that rely on these technologies which will now work with Bun.

Empty environment variables now appear as an empty string ("")

In process.env and Bun.env, empty environment variables appeared as undefined instead of an empty string. This is fixed, thanks to @liz3.

dns.lookupService is now implemented

The node:dns function dns.lookupService is now implemented. Thanks to @Hanaasagi.

console.log() depth is now 2 instead of 8

8 was nice, but caused issues with large objects filling up your terminal screen. Thanks to @JibranKalia. This aligns the behavior with Node.js.

node_api_create_external_string_latin1 and node_api_create_external_string_utf16

The node_api functions node_api_create_external_string_latin1 and node_api_create_external_string_utf16 are now implemented

listen() in node:http callback bugfix

The error event was not emitting to the event listener correctly. Thanks to @SuperAuguste for fixing this.

Bugfixes

Crash in request.json() fixed

A crash that could occur when calling request.json() was fixed. It was caused by incorrect exception handling in native code.

bun pm rm cache now works

The bun pm rm cache command now deletes the cache directory. Thanks to @WingLim.

Max redirect URL length is now 8192 instead of 4096

This fixes an issue with certain private npm registries.

bunx choosing version from $PATH instead of @version tag bugfix

A bug causing bunx to choose the version of the executable from $PATH instead of the @version tag was fixed

Full changelog

#4652VSCode Extension Bunlock Syntax-Highlighting and Docs Improvements by @JeremyFunk
#5451docs(runtime): fix some typo. by @zongzi531
#5531Update development.md by @sonyarianto
#5525fix(corking) uncork if needed by @cirospaciari
#5503fix(request) handle undefined/null/empty signal on request by @cirospaciari
#5521fix(bundler): Add a space before minified require by @davidmhewitt
#5505fix(node/fs.watch): Check first char before trimming event filenames by @davidmhewitt
#5535webkit upgrade by @dylan-conway
#5555Follow-up for workspace docs #5379 and #5229 by @bdenham
#5579fix: ArrayBufferConstructor type signature by @52
#5580fix: array-buffer.test-d.ts test by @52
#4693fix: node compatibility with empty path string (stat, exist, ...) by @coratgerl
#5603Make error message when importing a node: module in a browser bundle clearer by @Jarred-Sumner
#5576docs: fix typo in lockflie nav by @Vilsol
#5593Docs: path aliases fix by @e253
#5496fix(fetch) handle 100 continue by @cirospaciari
#5387feat(encoding): TextDecoder support undefined by @WingLim
#5481fix(child_process) unref next tick so exit/close event can be fired before application exits by @cirospaciari
#5529Implement VSCode tasks for bun by @JeremyFunk
#5610fix(install): Return NotSupported when errno == XDEV by @pan93412
#5510Fix ZLS commit hash in the document by @shinichy
#5628Added .DS_Store to gitignore-for-init by @Cilooth
#5615Workaround #5604 by @Jarred-Sumner
#5626Fix a TypeError in the documentation by @LapsTimeOFF
#5656Add a way to disable the GC timer by @Jarred-Sumner
#5660Remove hardcoded references to zig in Makefile by @xbjfk
#5595feat(console.log): Print anonymous when class name is unknown by @JibranKalia
#5572feat(test): Implement arrayContaining by @WingLim
#5655In bun:sqlite, make sure we set the number tag correctly when creating the JSValue by @Jarred-Sumner
#5662fix(config): support for registry url without trailing slash by @Hanaasagi
#5685fix(docs): update formatting by @rauny-brandao
#5638docs: add missing options from bun init by @jumoog
#5594change circles for color-blinds by @Hamcker
#5689Fix HTTP listen behavior being non-compliant with node by @paperdave
#5448feat(runtime): Implement console.Console by @paperdave
#5675Implement node_api_create_external_string_latin1 by @Jarred-Sumner
#5699fix(runtime/node): Allow new Buffer.alloc() + Upgrade WebKit by @paperdave
#5684fix: remove unneeded branch in toJSONWithBytes by @liz3
#5696update llvm version from 15 to 16 in makefile by @nithinkjoy-tech
#5679fix: provide empty string to 0 length process environment variables by @liz3
#5025bun run fix missing script error on empty file by @Parzival-3141
#5444Add navigator type definition by @ruihe774
#5716Encode slashes in package names in the registry manifest request by @Jarred-Sumner
#5726Make bun install --verbose more verbose by @Jarred-Sumner
#5730Fixes #3712 by @Jarred-Sumner
#5729Align fetch() redirect behavior with spec by @Jarred-Sumner
#5744Get artifactory to work by @Jarred-Sumner
#5702docs: Update Remix guide by @brookslybrand
#5620Added react installation to react.md by @jt3k
#5597remind users of the latest version by @jumoog
#5562docs: update net node documentation by @weyert
#5513docs(development): typo which would lead to wrong llvm installation by @sum117
#5759Doc updates by @colinhacks
#4571fix(cli): bun pm cache rm command not work by @WingLim
#5762fix(Makefile) by @cirospaciari
#5775Fixes #5769 by @Jarred-Sumner
#5447add warning to Ensure correct placement of the '--watch' flag by @a4addel
#5456Updated modules.md to address issue #5420 by @h2210316651
#4810docs: add Qwik guide by @sanyamkamat

New contributors

Thanks to Bun's newest contributors!

  • @52 made their first contribution in https://github.com/oven-sh/bun/pull/5579
  • @a4addel made their first contribution in https://github.com/oven-sh/bun/pull/5447
  • @AaronDewes made their first contribution in https://github.com/oven-sh/bun/pull/4779
  • @bdenham made their first contribution in https://github.com/oven-sh/bun/pull/5555
  • @brookslybrand made their first contribution in https://github.com/oven-sh/bun/pull/5702
  • @Brooooooklyn made their first contribution in https://github.com/oven-sh/bun/pull/5788
  • @Cilooth made their first contribution in https://github.com/oven-sh/bun/pull/5628
  • @coratgerl made their first contribution in https://github.com/oven-sh/bun/pull/4693
  • @ggobbe made their first contribution in https://github.com/oven-sh/bun/pull/5786
  • @h2210316651 made their first contribution in https://github.com/oven-sh/bun/pull/5456
  • @Hamcker made their first contribution in https://github.com/oven-sh/bun/pull/5594
  • @igorshapiro made their first contribution in https://github.com/oven-sh/bun/pull/5873
  • @ImBIOS made their first contribution in https://github.com/oven-sh/bun/pull/5885
  • @JeremyFunk made their first contribution in https://github.com/oven-sh/bun/pull/4652
  • @JibranKalia made their first contribution in https://github.com/oven-sh/bun/pull/5595
  • @jonahsnider made their first contribution in https://github.com/oven-sh/bun/pull/5104
  • @jt3k made their first contribution in https://github.com/oven-sh/bun/pull/5620
  • @jumoog made their first contribution in https://github.com/oven-sh/bun/pull/5638
  • @liz3 made their first contribution in https://github.com/oven-sh/bun/pull/5684
  • @nithinkjoy-tech made their first contribution in https://github.com/oven-sh/bun/pull/5696
  • @pan93412 made their first contribution in https://github.com/oven-sh/bun/pull/5610
  • @rauny-brandao made their first contribution in https://github.com/oven-sh/bun/pull/5685
  • @ruihe774 made their first contribution in https://github.com/oven-sh/bun/pull/5444
  • @sanyamkamat made their first contribution in https://github.com/oven-sh/bun/pull/4810
  • @shinichy made their first contribution in https://github.com/oven-sh/bun/pull/5510
  • @sum117 made their first contribution in https://github.com/oven-sh/bun/pull/5513
  • @Vilsol made their first contribution in https://github.com/oven-sh/bun/pull/5576
  • @weyert made their first contribution in https://github.com/oven-sh/bun/pull/5562
  • @xbjfk made their first contribution in https://github.com/oven-sh/bun/pull/5660
  • @yadav-saurabh made their first contribution in https://github.com/oven-sh/bun/pull/5270