DEV Community

Cover image for The best feature of Bun is not performance-related
Michał Kuncio
Michał Kuncio

Posted on • Edited on • Originally published at michalkuncio.com

1

The best feature of Bun is not performance-related

What is Bun?

Oh, you know what it is 😉 Let's skip this SEO filler and get straight to the point. The best feature of Bun is how it handles...

Module resolution

Anyone who has tried using Node.js with ESM or Typescript surely knows what I'm talking about.

  • should I use JS or MJS extension?
  • if so should I use type: module inside package.json?
  • should I use node --experimental-modules flag while running the app?
  • ok but what about TypeScript? We have compilerOptions.module there...
  • and what If I want to mix ESM and CJS?

The list goes on and on...

In Bun, you can forget about that madness.

  • Want to use ESM? Bun handles it
  • Want to use CJS? Bun handles it
  • Want to use JSX/TSX out of the box? Bun handles it

⭐️ And the most important thing:

You can mix ESM and CJS imports inside a single file! 🤯

import StuffESM from "./some-esm-module";
const StuffCJS = require("./some-cjs-module.cjs");
Enter fullscreen mode Exit fullscreen mode

This can be really handy while using some non-ESM node/express packages.

Summary

I'm excited about the future of Bun. It has many great features that are widely discussed in the tech space right now. I'm happy that we have 3 serious runtimes (Node, Deno, Bun) because the competition between them should be beneficial to everyone. Don't want to make a switch to Bun/Deno? Thanks to that competition, Node will probably be much better in the next versions and you won't have to switch. Exciting times ahead!

⭐ If you like my posts, please follow me on Twitter:
https://twitter.com/michalkuncio

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay