If you’ve paid any attention to the world of JavaScript web development lately, you’ll know that Vanilla JavaScript and Bun are taking the community by storm, with major projects, like Turbo and Svelte, switching from TypeScript to JavaScript with JSDoc for IDE-level typing. As someone who is currently learning TypeScript, I now am even more lost on whether I should continue or return to vanilla JavaScript.
However, I’m here to talk about Bun, the JavaScript runtime and package manager that is a direct competitor to Node.js. Bun’s package manager is 33x faster than Yarn, 29x faster than npm, and 17x faster than pnpm. Although Bun’s runtime is advertised to be faster as well, Next.js currently only supports Bun as a package manager so that’s all I’ve used so far.
Here are my results from switching from npm to bun package manager with Next.js on Vercel:
*I use the legacy-peer-deps flag to resolve some janky React dependencies.
Next.js Build | $ npm install | $ bun install |
Package Quantity | 457 | 456 |
Time (s) | 32 | 2.73 |
Switching from npm to bun resulted in an 11.72x speed increase.
Getting Started with Bun Package Manager
At the time of writing, Bun is available on Mac, Linux, and WSL. They have limited Windows support, so I’d recommend just using WSL. The installation for all operating systems can be found here. If you’re using WSL, then here’s my quick setup guide:
Bun Package Manager - Quick Setup with WSL
Install
unzip and curl firstsudo apt-get install unzip curl
Then install
buncurl -fsSL https://bun.sh/install | bash
To get started, run:
source /$HOME/$USER/.bashrc bun --help
Upgrade
bunbun upgrade
Install packages with
bunbun install
This will create a
bun.lockb file in your root directory. Vercel will pick up on this and automatically run bun install instead of npm install when building your Next.js website. You can remove the package-lock.json file to avoid any conflicts with npm.