Node 23: The Game Changer in Node.js
Node.js has come a long way, and with the release of Node 23, a new experimental version, the game has changed. Node 23 has gotten rid of one of the worst errors that developers could possibly see, and it's a game-changer.
In this new version, the inequality between CommonJS (CJS) and ECMAScript Modules (ESM) has been addressed. Previously, ESM could import CJS, but CJS couldn't import ESM directly. This led to a lot of refactoring and workarounds, but with Node 23, this issue is now a thing of the past.
In Node 23, you can now use require
and import
interchangeably, making it much easier to work with both CJS and ESM. This means that you can import ESM modules in CJS files and vice versa, without having to worry about the compatibility issues.
The Power of Interchangeable Require and Import
However, there is a catch. If you use top-level await in an ESM module, you'll get an error. This is because top-level await is not compatible with the synchronous nature of CJS.
The Limitation of Top-Level Await
To get around this limitation, you can use a flag in Node 22 to enable experimental support for ESM modules. This allows you to use the new behavior in Node 22, but with the caveat that it's still experimental.
Enabling Experimental Support for ESM Modules
In conclusion, Node 23 is a game-changer for Node.js developers. It addresses the inequality between CJS and ESM, making it much easier to work with both module systems. However, it's still experimental, and there are limitations to be aware of.
The Future of Node.js with Node 23
If you're interested in learning more about Node.js and TypeScript, be sure to check out the resources mentioned in the video, including Joyee Cheung's article on the topic and Matt Pocock's free TypeScript course.