---
title: Bun v1.0.4
description: Bun v1.0.4 fixes 62 bugs, adds `server.requestIP`, supports virtual modules in runtime plugins, fixes many bun install bugs, and reduces memory consumption in `Bun.serve()`
date: "2023-10-03T12:00:00.000Z"
author: jarred
draft: false
---

Bun v1.0.4 fixes 62 bugs, adds `server.requestIP`, supports virtual modules in runtime plugins, and reduces memory consumption in `Bun.serve()`. 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 &mdash; 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`](/blog/bun-v1.0) - Bun's first stable release!
- [`v1.0.1`](/blog/bun-v1.0.1) - Named imports for .json & .toml files, bugfixes to bun install, node:path, Buffer
- [`v1.0.2`](/blog/bun-v1.0.2) - Make `--watch` faster, plus bug fixes
- [`v1.0.3`](/blog/bun-v1.0.3) - `emitDecoratorMetadata`, Nest.js support, private registry fixes, and many bugfixes

To install Bun:

{% codetabs %}

```sh#curl
$ curl -fsSL https://bun.sh/install | bash
```

```sh#npm
$ npm install -g bun
```

```sh#brew
$ brew tap oven-sh/bun
$ brew install bun
```

```sh#docker
$ docker pull oven/bun
$ docker run --rm --init --ulimit memlock=-1:-1 oven/bun
```

{% /codetabs %}

To upgrade Bun:

```sh
$ bun upgrade
```

## Features

### Reduced memory usage in `Bun.serve()`

`Bun.serve()` now reports manually-managed per-request memory usage to JavaScriptCore's garbage collector. This reduces memory usage of `Bun.serve()` by 50% in some cases.

{% raw %}

<blockquote class="twitter-tweet"><p lang="en" dir="ltr">In the next version of Bun<br><br>Bun.serve() uses less memory<br><br>After 800k requests<br><br>Elysia<br>v1.0.4: 47 MB<br>v1.0.3: 71 MB<br><br>Fastify<br>v1.0.4: 114 MB<br>v1.0.3: 267 MB<br><br>Express<br>v1.0.4: 116 MB<br>v1.0.3: 167 MB <a href="https://t.co/XSjyo3aR9G">pic.twitter.com/XSjyo3aR9G</a></p>&mdash; Jarred Sumner (@jarredsumner) <a href="https://twitter.com/jarredsumner/status/1707355427904860475?ref_src=twsrc%5Etfw">September 28, 2023</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

{% /raw %}

### Implement `server.requestIP()`

With [`#6165`](https://github.com/oven-sh/bun/pull/6165), the IP address of a given `Request` can now be retrieved using `server.requestIP()`.

```ts
Bun.serve({
  port: 3000,
  handler: (req, res) => {
    console.log(server.requestIP(req));
  },
});
```

This does not read headers like `X-Forwarded-For` or `X-Real-IP`. It simply returns the IP address of the socket, which may correspond to the IP address of a proxy.

We've also added support to `node:http` for getting the socket address. `net.Socket().address` now returns an object with `address`, `port`, and `family` properties.

### Virtual modules in `Bun.plugin`

With [`#6167`](https://github.com/oven-sh/bun/pull/6167), Bun's plugin system gets more flexible and esbuild-compatible. It now supports fully virtual modules (`import stuff from "foo"`), in addition to custom loaders (`import stuff from "./stuff.foo"`).

You can register a virtual module by [registering a plugin](/docs/runtime/plugins#usage).

```ts
import { plugin } from "bun";

plugin({
  name: "my plugin",
  setup(builder) {
    builder.module("my-virtual-module", () => {
      return {
        exports: {
          hello: "world",
        },
        loader: "object",
      };
    });
  },
});
```

This virtual module can then be consumed like a normal module:

```ts
import { hello } from "my-virtual-module";
console.log(hello); // "world"

// require("my-virtual-module") also works
// await import("my-virtual-module") also works
// require.resolve("my-virtual-module") also works
```

This feature is currently only supported for runtime plugins, not `bun build`.

### Support parameters in `console.dir`

Thanks to [@liz3](https://github.com/liz3) for adding support for the second params object to `console.dir()` in [`#6059`](https://github.com/oven-sh/bun/pull/6059)

```ts
console.dir({ 1: { 2: { 3: 3 } } }, { depth: 0, colors: false });
```

## Potentially breaking changes

**`fetch()` & `bun install` now have a network timeout of 5 minutes instead of 30 seconds**

After a number of reports about `fetch()` & `bun install` timeout being too quick, we've increased the default timeout for `fetch()` from 30 seconds to 5 minutes. This aligns the default with Google Chrome and should help with high-latency connections. It also applies to `bun install`. Note that this timeout is not for the cumulative time of the request, but rather the time between each chunk of data received. If you want to disable the timeout entirely, you can pass `timeout: false` to `fetch()`.

**`bun install` now stores the package.json `"version"` field of workspace member packages in the lockfile**

Previously, `bun install` would infer the package.json versions from other existing data when retrieved next, but this turned out to not work very well because you don't always need the package.json version of workspace member packages (they might not have one). The lockfile now stores the package.json version of workspace member packages, which helps address an issue where having a dependency using the npm version in the package.json but referencing the local workspace version would cause `bun install` to fail.

This is an incremental update to the existing lockfile in-place, it should have no impact other than a dirty git status the next time a lockfile which has workspace member packages with a `version` set. This is not technically a breaking change because this didn't work before, but it feels worth noting.

## `bun install` bugfixes

Several stability improvements, including to workspaces, have been made to `bun install`:

- Fix `bun add <package>` when run inside a workspace member package [`#6092`](https://github.com/oven-sh/bun/pull/6092)
- Fix `bun install` "forgetting" about the existence of a workspace after the initial install
- Fixed a bug impacting Git/GitHub dependencies when the branch name contained a slash [`#5941`](https://github.com/oven-sh/bun/pull/5941).
- Fix occasional hang in `bun install` [`#6192`](https://github.com/oven-sh/bun/pull/6192)
- Support local `.tgz` dependency [`#5812`](https://github.com/oven-sh/bun/issues/5812)
- Fix a determinism bug that could happen when saving a lockfile, causing `git status` to report a dirty working tree when nothing actually changed.

## Major bugfixes

### Fix a bug causing `fetch` to timeout in some cases with 3xx status codes

There was a bug where `fetch` would timeout in certain cases involving 3xx status codes and empty bodies when some headers were not included. The request would complete, but would eventually timeout instead of reporting success. This also impacted `bun install` in certain cases.

### Fix `captureStackTrace` for subclasses of `Error` without `super()`

[#6063](https://github.com/oven-sh/bun/pull/6063) fixes a crash when using `captureStackTrace` inside a constructor without `super()` in extended classes.

```ts
class ExtendedError extends Error {
  constructor() {
    super();
    Error.captureStackTrace(this, ExtendedError);
  }
}

class AnotherError extends ExtendedError {}

throw new AnotherError();
```

### Fix a DNS resolution bug causing "Connection Refused" errors

Our usage of `getaddrinfo` was incorrect when the first returned result would fail to connect. `getaddrinfo` returns a linked list of results, but we were only looking at the first one. Now we look at all of them.

### Implement `isBinary` in `'connection'` callback for `ws`

Per [`#5944`](https://github.com/oven-sh/bun/pull/5944):

```ts
import WebSocket, { WebSocketServer } from "ws";

const wss = new WebSocketServer({
  port: 3000,
});

wss.on("connection", (ws) => {
  ws.on("message", (data, isBinary) => {
    // isBinary is now implemented
    console.log("received", data, isBinary);
  });
});
```

## Node.js compatibilitiy improvements

- Several bugs impacting Next.js pages router have been fixed, thanks to [@paperclover](https://github.com/paperclover)
- `util.inspect` has been rewritten to be more compatible with Node.js, thanks to [@jhmaster](https://github.com/jhmaster)
- A bug on macOS where `fs.rm` would not remove write-protected files has been fixed
- A bug where the callback version of `fs.exists` would mistakenly include an `error` parameter has been fixed, thanks to [@Hanaasagi](https://github.com/Hanaasagi)

## Changelog

{% table %}

---

- [`#5903`](https://github.com/oven-sh/bun/pull/5903)
- fix(runtime): exclude unevaluated module in `require.cache` by [@Hanaasagi](https://github.com/Hanaasagi)

---

- [`#5941`](https://github.com/oven-sh/bun/pull/5941)
- [install] fix GitHub dependency bugs by [@dylan-conway](https://github.com/dylan-conway)

---

- [`#5944`](https://github.com/oven-sh/bun/pull/5944)
- isBinary by [@dylan-conway](https://github.com/dylan-conway)

---

- [`#5986`](https://github.com/oven-sh/bun/pull/5986)
- Fixes #5985 by [@Jarred-Sumner](https://github.com/Jarred-Sumner)

---

- [`#5950`](https://github.com/oven-sh/bun/pull/5950)
- Use c-ares function for checking if a string is an IP address by [@Jarred-Sumner](https://github.com/Jarred-Sumner)

---

- [`#6000`](https://github.com/oven-sh/bun/pull/6000)
- Correctly fix #5888 by [@Jarred-Sumner](https://github.com/Jarred-Sumner)

---

- [`#6001`](https://github.com/oven-sh/bun/pull/6001)
- Do not use removefileat() by [@Jarred-Sumner](https://github.com/Jarred-Sumner)

---

- [`#6026`](https://github.com/oven-sh/bun/pull/6026)
- fix latest dev build panic by [@Hanaasagi](https://github.com/Hanaasagi)

---

- [`#6013`](https://github.com/oven-sh/bun/pull/6013)
- Fix create command with template prefixed with @ char #6007 by [@axlEscalada](https://github.com/axlEscalada)

---

- [`#6030`](https://github.com/oven-sh/bun/pull/6030)
- Add fs.statfs{Sync} to missing fs apis by [@techvlad](https://github.com/techvlad)

---

- [`#6032`](https://github.com/oven-sh/bun/pull/6032)
- Make error message for `new URL(invalid)` better by [@Jarred-Sumner](https://github.com/Jarred-Sumner)

---

- [`#5998`](https://github.com/oven-sh/bun/pull/5998)
- Add `Module._extensions` by [@Jarred-Sumner](https://github.com/Jarred-Sumner)

---

- [`#6036`](https://github.com/oven-sh/bun/pull/6036)
- Drain microtasks at end of abort() if called into JS by [@Jarred-Sumner](https://github.com/Jarred-Sumner)

---

- [`#6063`](https://github.com/oven-sh/bun/pull/6063)
- fix `captureStackTrace` inside constructor without `super` in extended by [@dylan-conway](https://github.com/dylan-conway)

---

- [`#5771`](https://github.com/oven-sh/bun/pull/5771)
- Improve Docker images by [@Electroid](https://github.com/Electroid)

---

- [`#6090`](https://github.com/oven-sh/bun/pull/6090)
- fix: Docker - Include `bunx` symlink in distroless variant by [@polarathene](https://github.com/polarathene)

---

- [`#6086`](https://github.com/oven-sh/bun/pull/6086)
- fix(fetch/server) fix server end of stream, fix fetch not streaming without content-length or chunked encoding, fix case when stream do not return a promise on pull by [@cirospaciari](https://github.com/cirospaciari)

---

- [`#6059`](https://github.com/oven-sh/bun/pull/6059)
- fix: support console.dir options object correctly by [@liz3](https://github.com/liz3)

---

- [`#6092`](https://github.com/oven-sh/bun/pull/6092)
- fix workspace dependency install by [@dylan-conway](https://github.com/dylan-conway)

---

- [`#6097`](https://github.com/oven-sh/bun/pull/6097)
- fix(node:fs): fix `fs.exists` callback parameters by [@Hanaasagi](https://github.com/Hanaasagi)

---

- [`#6100`](https://github.com/oven-sh/bun/pull/6100)
- fix: Docker - Apply workaround with `RUN` to symlink `bunx` by [@polarathene](https://github.com/polarathene)

---

- [`#5825`](https://github.com/oven-sh/bun/pull/5825)
- fix: implement correct behaviour for urls with blob: scheme by [@liz3](https://github.com/liz3)

---

- [`#6122`](https://github.com/oven-sh/bun/pull/6122)
- fix(bun install): Handle vercel and github tarball path dependencies by [@booniepepper](https://github.com/booniepepper)

---

- [`#6123`](https://github.com/oven-sh/bun/pull/6123)
- revert fix for passing empty env vars to `bun run` by [@dylan-conway](https://github.com/dylan-conway)

---

- [`#5932`](https://github.com/oven-sh/bun/pull/5932)
- `deadCodeElimination` toggle for Bun.Transpiler by [@jhmaster2000](https://github.com/jhmaster2000)

---

- [`#6130`](https://github.com/oven-sh/bun/pull/6130)
- fix typescript metadata for import identifiers by [@dylan-conway](https://github.com/dylan-conway)

---

- [`#4493`](https://github.com/oven-sh/bun/pull/4493)
- Complete rework of the majority of `node:util`, primarily `util.inspect` by [@jhmaster2000](https://github.com/jhmaster2000)

---

- [`#6095`](https://github.com/oven-sh/bun/pull/6095)
- Get Next.js Pages Router to work by [@paperclover](https://github.com/paperclover)

---

- [`#6135`](https://github.com/oven-sh/bun/pull/6135)
- Reduce memory usage of HTTP server by [@Jarred-Sumner](https://github.com/Jarred-Sumner)

---

- [`#6118`](https://github.com/oven-sh/bun/pull/6118)
- Add local tarball install #5812 by [@axlEscalada](https://github.com/axlEscalada)

---

- [`#6158`](https://github.com/oven-sh/bun/pull/6158)
- Upgrade to latest Node.js version by [@Jarred-Sumner](https://github.com/Jarred-Sumner)

---

- [`#6162`](https://github.com/oven-sh/bun/pull/6162)
- Fixes #6053 by [@Jarred-Sumner](https://github.com/Jarred-Sumner)

---

- [`#6165`](https://github.com/oven-sh/bun/pull/6165)
- feat(runtime): implement `server.requestIp` + node:http `socket.address()` by [@paperclover](https://github.com/paperclover)

---

- [`#5766`](https://github.com/oven-sh/bun/pull/5766)
- fix(resolver): support encoded file urls by [@paperclover](https://github.com/paperclover)

---

- [`#5945`](https://github.com/oven-sh/bun/pull/5945)
- fix(runtime): Socket.prototype is undefined by [@paperclover](https://github.com/paperclover)

---

- [`#6154`](https://github.com/oven-sh/bun/pull/6154)
- fix: don't set default request method when creating a Request from another by [@liz3](https://github.com/liz3)

---

- [`#6185`](https://github.com/oven-sh/bun/pull/6185)
- fix(runtime): followup for `server.requestIP` by [@paperclover](https://github.com/paperclover)

---

- [`#6167`](https://github.com/oven-sh/bun/pull/6167)
- Implement virtual module support in `Bun.plugin` by [@Jarred-Sumner](https://github.com/Jarred-Sumner)

---

- [`#6192`](https://github.com/oven-sh/bun/pull/6192)
- Fix hang in `bun install` by [@Jarred-Sumner](https://github.com/Jarred-Sumner)

---

- [`#6195`](https://github.com/oven-sh/bun/pull/6195)
- tweak github actions by [@Jarred-Sumner](https://github.com/Jarred-Sumner)

---

- [`#6206`](https://github.com/oven-sh/bun/pull/6206)
- Fix bug causing "Connection Refused" errors by [@Jarred-Sumner](https://github.com/Jarred-Sumner)

---

- [`#6207`](https://github.com/oven-sh/bun/pull/6207)
- fix(node:process): fix return value of `process.kill` by [@Hanaasagi](https://github.com/Hanaasagi)

---

- [`#6219`](https://github.com/oven-sh/bun/pull/6219)
- Slightly reduce number of open file descriptors in `bun install` by [@Jarred-Sumner](https://github.com/Jarred-Sumner)

---

- [`#6231`](https://github.com/oven-sh/bun/pull/6231)
- Added the fileExtensions field to file-system-router.md by [@cornedor](https://github.com/cornedor)

---

- [`#6242`](https://github.com/oven-sh/bun/pull/6242)
- Warn at start when using AVX build of Bun without AVX support by [@Jarred-Sumner](https://github.com/Jarred-Sumner)

---

- [`#6247`](https://github.com/oven-sh/bun/pull/6247)
- Fix `bun install` reading Github API from wrong environment variable by [@Electroid](https://github.com/Electroid)

---

- [`#6217`](https://github.com/oven-sh/bun/pull/6217)
- Set `fetch` timeout to 5 minutes by [@Jarred-Sumner](https://github.com/Jarred-Sumner)

{% /table %}

Thanks to Bun's newest contributors!

[@meck93](https://github.com/meck93) [@aszenz](https://github.com/aszenz) [@cyfung1031](https://github.com/cyfung1031) [@axlEscalada](https://github.com/axlEscalada) [@techvlad](https://github.com/techvlad) [@Dawntraoz](https://github.com/Dawntraoz) [@polarathene](https://github.com/polarathene) [@DarthDanAmesh](https://github.com/DarthDanAmesh) [@DevinJohw](https://github.com/DevinJohw) [@cornedor](https://github.com/cornedor) [@ciceropablo](https://github.com/ciceropablo)

**Full Changelog**: https://github.com/oven-sh/bun/compare/bun-v1.0.3...bun-v1.0.4
