Bun

Bun v1.0.2


Jarred Sumner · September 15, 2023

Bun v1.0.2 fixes numerous bugs and makes bun --watch faster.

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

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

bunx <package>@latest always fetches the latest

Previously, bunx package@latest would only fetch the latest version of the package if it had not been installed previously in the /tmp folder (which is cleared every 3 days or on restart, dpending on your OS).

Now, bunx package@latest will always fetch the latest version of the package. If there is an @ tag and that tag is not a number, it will fetch the query the npm registry for the matching version of the package.

#5346

Faster bun --watch

bun --watch <./path-to-file.ts> lets you watch a file and re-run it when it or any of its imports change. This is useful for development.

Previously, bun --watch would enqueue a task to the event loop on change to reload the process. That means any blocking or long-running tasks would delay the reload.

Now, it reloads immediately.

In this gif, the current timestamp in milliseconds is printed to the console on restart.

bun run --silent no longer prints error messages

When running:

bun run --silent bash -c 'exit 1'

Before:

error: "bash" exited with code 1

After:

# nothing!

Bun now uses V8's Date parser

Bun now uses V8's Date parser. This means that date parsing behaves the same in Bun as it does in Chrome and Node.js.

Previously:

Date.parse("2020-09-21 15:19:06 +00:00"); // Invalid Date

After:

Date.parse("2020-09-21 15:19:06 +00:00"); // 1600701546000

This fixes a number of bugs where date parsing would fail in Bun but work in Node.js.

URL.canParse is implemented

The URL class now has a static canParse method, which returns true if the URL can be parsed, and false otherwise.

URL.canParse("https://example.com"); // true
URL.canParse("https://example.com:8080"); // true
URL.canParse("apoksd!"); // false

URL.canParse is a relatively new addition to the Web Platform. At the time of writing, it is not available in Chrome or Firefox yet.

URLSearchParams.prototype.size is implemented

The URLSearchParams class now has a size property, which returns the number of key/value pairs in the search params.

const params = new URLSearchParams("a=1&b=2&c=3");
params.size; // 3

URLSearchParams.prototype.size is a relatively new addition to the Web Platform.

Bugfix to bun run

Previously, bun run would always load tsconfig.json files. This meant that having an invalid tsconfig.json file could cause bun run to fail, which was completely unnecessary. THis has been fixed.

Bugfix to node:stream

When encoding was passed to the write function, the callback would not be called. This has been fixed.

#75b5c715405d49b5026c13143efecd580d27be1b

Bugfix to fetch with a data: URL

Previously, invalid data: URLs would throw an exception in fetch. This was inconsistent with Node.js which would leave the incorrect data in the URL. This has been fixed, thanks to @davidmhewitt.

#c3455c0ceee6bbe399781819a42fff6cf24792e2

Bugfix to node:readline (arrow keys)

A bug in node:readline causing the terminal to hang on WSL has been fixed.

#5345

Bugfix to node:dns

A crash in node:dns's resolve function has been fixed, thanks to @Hanaasagi.

#5200

os.availableParallelism is implemented

The node:os module now has an availableParallelism property, which returns the number of logical CPUs available to the process.

os.availableParallelism(); // 8

You can also use navigator.hardwareConcurrency.

Bugfixes to Bun.serve()

A crash that could occur when a ReadableStream has enqueued all data before the stream has begun being read has been fixed. This crash happened because the code was missing a check for whether or not a JavaScript function was a callable object.

#5321

A crash that could occur when calling req.formData() has been fixed

#4966

A bug causing the set-cookie header to be set incorrectly in node:http in some cases has been fixed. This causes issues with Express.js.

#5183

node:fs functions are now concurrent

Previously, only a handful of node:fs functions were concurrent. Now, all of them are.

Deletable setTimeout & other globals

Most globals are now configurable/deletable, which fixes issues impacting some libraries and ExecJS.

Bugfix for fastify

Fastify loops over require.cache during initialization. require.cache previously included ES Modules which have not finished evaluating yet and that partially broke Fastify. This has been fixed.

Bugfix for multiline string in CRLF terminated files

Thanks to @tikotzky for the fix.

#5318

Bugfix for Bun.file()

When the length of the file was less than the size of the Bun.file(), the file would sometimes not finish reading. This has been fixed, thanks to @cirospaciari.

#5186

Bugfix for node:tty

A bug causing WritableStream.prototype.getColorDepth to sometimes throw an exception has been fixed.

#5468

Transpiler bugfix for escaping non-ascii RegExp literals to latin1

#5468

Internal changes

We upgraded from LLVM 15->16 & Clang 15->16.

Full changelog

#5161fix(bun-lambda) Fix API Gateway V1 events and expand on Lambda documentation by @mkossoris
#5159fix lifecycle docu by @ximex
#5151docs: fix typos by @s-rigaud
#5127Updated Lambda readme by @tsndr
#5072Add missing full stop on nodejs-apis.md by @diogo405
#5069update dev build instruction for arch by @mi4uu
#5046fix typo and grammar errors in bunfig.toml by @xNaCly
#4997Update simple.md by @tomredman
#4990Update hot.md by @nazeelashraf
#5146docs: fix typo in import.meta.resolve by @jonathantneal
#5143[Docs] Use git's --global flag for lockfile diffs instead of manually editing config files. by @Southpaw1496
#5201Various docs by @colinhacks
#5120docs: Made bun-types install as dev dependency in example by @MasterGordon
#4841js/node/stream.js: call write() callback when encoding is not provided by @cfal
#5234Correct the configuration file names. by @nathanhammond
#5167decode regex if needed by @dylan-conway
#5227Update misleading documentation link by @0x346e3730
#5061file.exists() needs to be awaited to get the value by @amt8u
#5243docs(runtime): fix jsx FragmentFactory output example by @zongzi531
#5248Add informative message on bun create react by @colinhacks
#5140chore: make comment grammatically correct by @G-Rath
#5250docs(runtime): fix plugins loader extensions typo by @zongzi531
#5057avoid inserting extraneous"accept-encoding" header by @iidebyo
#5126fix(node/fetch): Make data URL fetch consistent with node by @davidmhewitt
#5275docs: update lockfile diff instructions by @gtramontina
#5311add uninstall instructions by @browner12
#5294docs(guide): fix expect assertion example in guide for spyOn by @winghouchan
#5281chore(docs): include missing links to Node.js APIs by @styfle
#5262Fixed api & cli docs typo. by @jamesgordo
#5233fix(runtime): require cache should not include unevaluated ESM modules. by @paperdave
#5236Make --watch instant by @Jarred-Sumner
#5109feat(nodejs): implement os.availableParallelism by @WingLim
#5164fix(console.log) fix printing long custom format by @cirospaciari
#5200fix(node:dns): fix crash and compatibility issues with resolve by @Hanaasagi
#5325fix(doc): Add "compilerOptions" to bun-types README.md by @philolo1
#5186fix(BunFile.slice) fix slice when length is greater than the size by @cirospaciari
#5229More docs & helptext cleanup by @colinhacks
#5285doc(guides): update sveltekit guide by @mroyme
#5225modules documentation didn't have correct import example by @miccou
#5115fix link to "local template" by @desm
#5244chore: test for overwriting _resolveFilename by @paperdave
#5318Fix bug with multiline string in CRLF terminated files (#4893) by @tikotzky
#5216fix(runtime): make most globals configurable/deletable, allow resuming the console iterator by @paperdave
#5152fix(Bun.serve) fix buffering edge case by @cirospaciari
#4905Update nextjs.md by @kryparnold
#4881Update simple.md by @TwanLuttik
#4452Update nuxt.md by @s0h311
#5335Remove the ability to configure lockfile location. by @nathanhammond
#5346In bunx, always get latest version when @latest is explicitly passed by @Jarred-Sumner
#5376Fix typo in HTTPThread name by @chrisbodhi
#5379docs - Add "workspace:*" to workspace docs. by @dylang
#4647fix(docs): Fix the text that bun run --bun is the same as bun by @DuGlaser
#5419fix warnings during bun run publish-layer by @nangchan
#5336fix(runtime): emit node:net connect error event vs throw by @paperdave
#5332v8 date parser tests by @dylan-conway
#5360async-ify all node:fs functions by @Jarred-Sumner
#5439fix dockerfile by @Jarred-Sumner
#5428fix http set cookie headers by @dylan-conway
#5422fix(nitro) fix sourcemaps and JSSink closing by @cirospaciari
#5425Update docs/quickstart.md by @sonyarianto
#5341dup and close file descriptors by @dylan-conway
#5459Make bun run --silent omit "error: "..." exited with code 1 by @Jarred-Sumner
#5452Does not fix #4622 by @Jarred-Sumner
#5464fix(proxy): allow empty string http_proxy env by @Hanaasagi
#5463Implement URL.canParse by @Jarred-Sumner
#5467Fixes #5461 by @Jarred-Sumner
#5468Fixes #5465 by @Jarred-Sumner

New contributors

Thanks to Bun's newest contributors!

@mkossoris @ximex @s-rigaud @tsndr @mi4uu @xNaCly @tomredman @nazeelashraf @jonathantneal @Southpaw1496 @MasterGordon @cfal @nathanhammond @0x346e3730 @amt8u @zongzi531 @G-Rath @iidebyo @gtramontina @browner12 @winghouchan @philolo1 @mroyme @miccou @desm @tikotzky @kryparnold @TwanLuttik @s0h311 @chrisbodhi @dylang @DuGlaser @nangchan @sonyarianto