Sitemap

Node.js 23 Release: Bridging the Gap with Bun.js Features

2 min readOct 20, 2024

--

Press enter or click to view image in full size

The latest release of Node.js 23 brings some exciting features to the table, particularly addressing one of the pain points that Bun.js had previously solved. Let’s dive into the key improvements and what they mean for developers.

ESM and CommonJS Interoperability by Default

One of the most significant updates in Node.js 23 is the default enabling of require for ESM (ECMAScript Modules). This feature, which was previously available behind a command-line flag in versions 20 and 22, is now enabled out of the box.

Why This Matters

The JavaScript ecosystem has long struggled with the coexistence of two module systems:

  • CommonJS (using require)
  • ESM (using import/export)

This division has caused numerous headaches for developers, particularly when working with packages that mix both formats. For example, the node-fetch package's higher versions exclusively use ESM, which previously caused compatibility issues with CommonJS codebases.

Code Example:

// Previously problematic, now works in Node.js 23
const package = require('esm-only-package');

// Mixed usage in the same file
import { feature } from './esm-module.js';
const legacy = require('./commonjs-module.js');
Press enter or click to view image in full size

Limitations

It’s important to note that there’s still one restriction: you cannot require a file that uses top-level await since the require function is inherently synchronous. This limitation exists in both Node.js and Bun.js.

Node Script Runner Stabilization

Another welcome addition is the stabilization of the node --run command. This feature allows developers to execute scripts defined in package.json directly through Node.js, similar to what package managers like npm, yarn, or pnpm offer.

Get Sabiqt’s stories in your inbox

Join Medium for free to get updates from this writer.

Before:

npm run test
yarn test
pnpm test

Now:

node --run test

Backwards Compatibility

Node.js is maintaining its commitment to stability by:

  • Backporting the unflagged ESM/CommonJS interoperability to Node.js 22
  • Making the stable script runner available in version 22 as well

This is particularly beneficial for environments like AWS Lambda, where you might not immediately have access to the latest Node.js version but still want to use these features.

What This Means for the Ecosystem

These updates show Node.js’s commitment to:

  1. Solving long-standing ecosystem pain points
  2. Providing better developer experience out of the box
  3. Keeping up with innovations introduced by newer runtimes like Bun.js

The ability to seamlessly use both ESM and CommonJS modules without flags or workarounds is a significant step forward for the JavaScript ecosystem, making it easier for developers to work with mixed codebases and dependencies.

These improvements in Node.js 23 demonstrate how healthy competition in the JavaScript runtime space drives innovation and better developer experiences across the ecosystem.

--

--