Heard of Bun? It's a new JavaScript runtime that recently reached 1.0.0. I've been using it on a few side-projects. Even at work!
Ok so what is a runtime? A runtime is the environment that your code runs in. For JavaScript that's your browser, an Electron app, or NodeJS. Compiled languages like C or C# don't need a runtime because the compiled binary runs natively on your machine.
Bun is a new runtime written from scratch. Optimized for performance, compatibility, and ease of use.
Things I've liked about Bun
A few things that stood out after using Bun for a few hours. I'm not an expert but so far Bun has been stupid easy to use.
Bun is very very fast
Using Bun feels faster. You have to try to appreciate the difference. It's like your computer feels lighter.
When you run a NodeJS script, it's fast. Hit enter and your script gets to work. No lag you'd complain about.
Then you run the same script with Bun and it's like omg what just happened? I barely finished hitting enter and it's done!? 🤯
No mjs bullshit
I don't know about you, but seeing Error [ERR_REQUIRE_ESM]: require() of ES Module
makes me want to throw keyboards. You add a new library and the whole project blows up. (╯°□°)╯︵ ┻━┻
This is because a few years ago NodeJS decided to support modern imports. import thing from 'file'
instead of const thing = require('file)
. Fantastic!
But they couldn't make both systems compatible. You have to choose between CommonJS (require) and Modules (import).
Some libraries have migrated. Many haven't. You'll find out which is which when your project blows up after you add a dependency 🙃
Bun doesn't have this problem. I don't know through what magic, but I like it. Everything just works.
Native TypeScript support
Write a file.ts
run with bun run file.ts
.
Write a file.js
run with bun run file.js
.
Direct native runtime support for TypeScript. No compiling, little configuration. Cross-import JavaScript into TypeScript and TypeScript into JavaScript. Bun don't care 😍
No run-time support for types though. Jarred, creator of Bun, says that's not a goal either.
Tools included
Bun aims to become a full toolkit for JavaScript.
the right side and the left side will look a lot more similar in less than a year https://t.co/awZsr0GhDD
— Jarred Sumner (@jarredsumner) October 11, 2023
Can't wait! The ease of going bun add library
and bun run code.ts
already feels amazing. Haven't looked for others yet.
Compatible with the NodeJS ecosystem
This has been my favorite part. Bun aims to work as a drop-in replacement for NodeJS, which means full ecosystem compatibility.
APIs you're used to from NodeJS all work. I haven't bumped into anything broken, at least not in side-projects. Every library I've tried has also worked.
Means you don't have to learn anything new \o/
A couple sharp edges
We all know how drop-in replacements work.
"Like Bun, it's a drop-in replacement" pic.twitter.com/IhXdmoMOTE
— Swizec Teller (@Swizec) October 17, 2023
If you use private packages, you'll have to move registry configuration from .npmrc
to bunfig.toml
. That's easy.
In larger projects, you're likely to find things that are broken. When I tried running work stuff in Bun, there was a cryptic error with no good way to debug. Later we figured out our Logger library, used everywhere, doesn't like Bun – an outdated dependency maybe.
Bun is new. Fantastic documentation, but if you run into a problem the documentation doesn't cover, you're likely one of the first people online to have this problem.
All in all, Bun is my new favorite way to write CLI scripts.
Cheers,
~Swizec
Continue reading about Bun – first impressions
Semantically similar articles hand-picked by GPT-4
- TypeScript runtime vs types at run-time
- Is JavaScript really getting too complex?
- Webpack lazy loading on Rails with CDN support
- Learn TypeScript in 5 minutes
- Use private libraries to cleanup your codebase
Learned something new?
Read more Software Engineering Lessons from Production
I write articles with real insight into the career and skills of a modern software engineer. "Raw and honest from the heart!" as one reader described them. Fueled by lessons learned over 20 years of building production code for side-projects, small businesses, and hyper growth startups. Both successful and not.
Subscribe below 👇
Software Engineering Lessons from Production
Join Swizec's Newsletter and get insightful emails 💌 on mindsets, tactics, and technical skills for your career. Real lessons from building production software. No bullshit.
"Man, love your simple writing! Yours is the only newsletter I open and only blog that I give a fuck to read & scroll till the end. And wow always take away lessons with me. Inspiring! And very relatable. 👌"
Have a burning question that you think I can answer? Hit me up on twitter and I'll do my best.
Who am I and who do I help? I'm Swizec Teller and I turn coders into engineers with "Raw and honest from the heart!" writing. No bullshit. Real insights into the career and skills of a modern software engineer.
Want to become a true senior engineer? Take ownership, have autonomy, and be a force multiplier on your team. The Senior Engineer Mindset ebook can help 👉 swizec.com/senior-mindset. These are the shifts in mindset that unlocked my career.
Curious about Serverless and the modern backend? Check out Serverless Handbook, for frontend engineers 👉 ServerlessHandbook.dev
Want to Stop copy pasting D3 examples and create data visualizations of your own? Learn how to build scalable dataviz React components your whole team can understand with React for Data Visualization
Want to get my best emails on JavaScript, React, Serverless, Fullstack Web, or Indie Hacking? Check out swizec.com/collections
Did someone amazing share this letter with you? Wonderful! You can sign up for my weekly letters for software engineers on their path to greatness, here: swizec.com/blog
Want to brush up on your modern JavaScript syntax? Check out my interactive cheatsheet: es6cheatsheet.com
By the way, just in case no one has told you it yet today: I love and appreciate you for who you are ❤️