Tutorial Apr 10, 2026 14 min read

ESM and CJS: A Practical Guide for Library Authors

Dual-format packages, the exports field, TypeScript moduleResolution — everything a library author needs to know to ship a package that just works.

If you maintain a JavaScript library in 2026, you almost certainly need to ship both ESM and CJS formats. This guide explains why, and shows you exactly how to configure your package to handle both cleanly.

Why Both Formats?

ESM (ECMAScript Modules) is the standard module format for the web platform and modern Node.js. CJS (CommonJS) is still used by millions of packages and tools that haven't migrated. Until the ecosystem fully converges on ESM, library authors need to ship both.

"Pure ESM packages break a huge number of existing build tools and older Node.js environments. Ship dual formats until you know your audience has moved on."

Node.js Module Team
Tags
TutorialESMnpmTypeScript
// RELATED POSTS

You might also like