Bun

Bun v1.0.1


Jarred Sumner · September 12, 2023

Bun v1.0.1 adds named imports for .json & .toml files, fixes a bug with bun install and error.PathAlreadyExists, fixes a bug importing node: builtins in bun build --compile, fixes a bug in relative() within node:path, fixes a bug where bun would load the wrong .env file, fixes a bug where tsconfig.json would be loaded in bun run <package.json script>, fixes a path.parse() bug, and fixes a bug where build errors would be printed twice.

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!

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

Named imports for .json & .toml files

When you import a .json or .toml file in Bun, you can now import the top-level keys directly.

import { name, version } from "./package.json";

console.log({ name, version }); // { name: "bun", version: "1.0.1" }

Previously, only the default export was supported.

import pkg from "./package.json";
const { name, version } = pkg;

console.log({ name, version }); // { name: "bun", version: "1.0.1" }

You can also import tsconfig.json files even if they have comments. This internally uses Bun's JSONC parser.

import { paths } from "./tsconfig.json";

console.log(paths); // { "paths": { "b": ["./a.js"] } }

You can continue to use the default export if you prefer. The named import values are === to the default export's value at the same key.

import boop, { array } from "./file.json";

console.log(boop.array === array); // true

This all works with require as well.

bun install bug with error.PathAlreadyExists

A bug was fixed where bun install would fail with error.PathAlreadyExists when installing a package via hardlink.

Bug importing node: builtins in bun build --compile fixed

Bun 1.0 added a regression where importing node: builtins in bun build --compile would fail. This has been fixed.

// This failed in `bun build --compile`! It should not have.
import "node:fs/promises";

Bug in relative() within node:path

Previously, the following would print "":

console.log(path.relative("../", "../../"));

Now it correctly prints .., thanks to @Hanaasagi.

Bug where bun would load the wrong .env file

When you run bun in a nested bun run package.json script, bun would potentially load the wrong NODE_ENV variable. This has been fixed.

https://github.com/oven-sh/bun/pull/4630

tsconfig.json no longer loaded in bun run <package.json script>

Previously, bun would load the tsconfig.json file in the current working directory when running a package.json script. There was no need to do this. It just wasted your time. We shouldn't do that. So we don't load tsconfig.json for package.json "scripts". Note that we still load it for the runtime, just not when running a package.json script.

Build errors printed twice bug

A bug was fixed where build errors would be printed twice.

Bun.file() .slice offset on macOS bug

A bug was fixed where Bun.file().text(), when using .slice() to offset the buffer, would in certain cases not have seek the data to the expected position

Buffer.from with a UTF-16 encoded hex

A bug was fixed where Buffer.from would not correctly handle hex strings from a UTF-16 encoded source.

Thanks to @Hanaasagi for fixing this.

Disable TLS verification using NODE_TLS_REJECT_UNAUTHORIZED

Bun now supports disabling TLS verification using NODE_TLS_REJECT_UNAUTHORIZED. This is useful for testing, but should not be used in production.

Set NODE_TLS_REJECT_UNAUTHORIZED=0 to disable TLS verification.

NODE_TLS_REJECT_UNAUTHORIZED=0 bun run ./server.js

Thanks to @cirospaciari.

path.parse() bug

The path.parse() function was not correctly cloning the output strings. This has been fixed, thanks to @davidmhewitt.