Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Bun 5 min read Opinion mediumAdept

CommonJS is not going away

CommonJS remains the dominant format on npm (about 74% of popular packages in late 2022), so Bun now implements it natively as of v0.6.5 instead of transpiling it to a synchronous ESM form. CommonJS loads faster because ES modules need two passes, parsing and linking the whole graph before evaluation, to support live bindings. In Bun, requiring Babel is about 2.4x faster than importing it (85ms saved, versus 1.8x / ~60ms in Node.js), which matters for serverless cold starts. Bun supports importing CommonJS from ESM, including the de-facto `__esModule` annotation that maps `exports.default` to the default import.

Related posts

  • Bun v0.6.10

    Bun mediumAdept

    Bun v0.6.10 rewrites CommonJS module loading for better Node.js compatibility. That gets webpack working and adds `require.main`, `process.mainModule`, and runtime support for the `__esModule` annotation, which preserves default exports when CJS output from bundlers is re-imported as ESM. That behaviour is disabled when no annotation is present or the package type is "module". The release also adds `bun test` matchers (resolves/rejects, toBeArray, toBeTypeOf) and `spyOn()`, `fs.watch()`, `fs.readv`/`writev`, and more of the V8 stack trace API. It fixes `.env` parsing and a latin1 truncation bug in the WebSocket client, and adds `bun install --exact`, `--frozen-lockfile`, and a `trustedDependencies` allow-list for lifecycle scripts.

  • Bun v0.6.5

    Bun mediumAdept

    Bun reimplements CommonJS as native runtime support instead of transpiler-only wrapping. Detected CJS modules are wrapped in a (module, exports, require) function, evaluated, and their exports appended as named ES Module exports, which fixes `export * from`, sloppy-mode code and packages like Vue, Winston and viem. The release also improves CJS-to-ESM conversion in Bun.build(), adds $npm_lifecycle_event to bun run, and ignores SIGPIPE to stop crashes when streaming files to disconnected clients. It also fixes node:net createConnection argument parsing and a transpiler bug that turned Symbol["for"] into undefined.

  • Bun v0.7.1

    Bun mediumAdept

    Bun v0.7.1 makes ES Module loading 30%–250% faster by running its transpiler concurrently for import statements and dynamic imports, though CommonJS require is still sequential. Module resolution now happens only once, at runtime. The release also cuts vite dev startup on Linux by 90%, speeds up bun:sqlite row returns by 10%, and fixes getaddrinfo handling so private registries like Verdaccio work. Node.js compatibility fixes cover fs.watch thread usage, fs.stat truncation on large files, a GC bug in fs.readdir, and making the event loop wait for WebAssembly, Atomics and Web Crypto work, alongside new MessageChannel, fetch file: URLs and Promise.withResolvers support.

  • CommonJS is hurting JavaScript

    Deno easyNovice

    CommonJS, born in 2009 from the ServerJS effort to give server-side JavaScript a module system, became Node's default but carries core flaws: synchronous loading, poor tree-shaking, and no native browser support. ECMAScript modules fix these as a web-first standard, yet Node's decision to support both systems pushed the interoperability burden onto package authors, who must ship complex dual ESM/CJS package.json configurations. The argument is to abandon CommonJS for an all-ESM future, with tools like dnt as a stopgap for dual publishing.

  • Bun v0.6.7

    Bun mediumAdept

    Bun v0.6.7 fixes Node.js compatibility bugs in Node-API, node:http, undici, WebSocket, node:net and CommonJS/ESM interop, which lets Prisma, Discord.js and Puppeteer run in Bun. It also roughly doubles node:crypto hashing speed on small inputs and fixes regressions from the native CommonJS rewrite, including a scope-lifetime crash and incorrect __dirname/__filename injection. Two known CommonJS differences from Node.js remain: module evaluation order, and Bun's runtime-based detection of named exports instead of static analysis. Bundler fixes cover __esModule handling, jsx vs jsxDEV selection, bun build --compile and JSON default imports.

The quest for software engineering knowledge.

Look:
Layout: