ESM-Only Packages: What Has Changed and Why

A few years ago, publishing a package that could only be loaded with import was controversial and generated angry issues from CommonJS users. Today it is an ordinary choice for new libraries. The change did not happen through one announcement; it is the result of several developments stacking up.

The developments behind the shift

  1. Stable ESM in Node.js. Node.js has supported ES modules without flags since the 12.x and 14.x era, together with the "type": "module" field and the exports map for controlling entry points. Every currently supported Node.js release line has mature ESM support.
  2. Old runtimes reaching end of life. As release lines without good ESM support dropped out of the Node.js support schedule, the number of users who could not load ESM at all shrank.
  3. Tools defaulting to ESM. Modern bundlers, test runners and TypeScript's newer module resolution settings treat ESM as the primary format.
  4. Loading ESM from CommonJS. Recent Node.js releases added the ability to require() an ES module in many cases, removing the hardest objection: that an ESM-only dependency forced the entire consuming app to convert. The exact versions and limitations are documented in the Node.js modules documentation; check them for your target runtime.

What an ESM-only package looks like

{
  "name": "@example/parse-thing",
  "version": "3.0.0",
  "type": "module",
  "exports": {
    ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" }
  },
  "engines": { "node": ">=20" },
  "files": ["dist"]
}

One build, one set of types, one entry point. The engines field documents the runtime assumption; choose the minimum that matches the Node.js versions you test against.

What has not changed

Some constraints remain. Code that loads modules synchronously at runtime in unusual ways, older test setups that rely on CommonJS mocking, and some serverless or plugin hosts may still expect CommonJS. ES modules with top-level await cannot be loaded through require(). And users pinned to older runtimes for operational reasons will stay on your last dual or CommonJS major for a while, so they need security fixes there too.

Signals that the shift is real

You can watch the change without relying on anyone's survey. Open the package.json of the dependencies you already use and note how many declare "type": "module" and expose only an import condition. Read the release notes of the tools in your build chain and see which format they now treat as primary. Check the documentation of your test runner for how it handles native ESM. These are first-hand observations about your own dependency tree, and they are a better guide to your next decision than any general claim about the ecosystem as a whole.

How to respond

As an author: if you go ESM-only, do it in a major release, state the minimum runtime, keep the previous major patched for a period you announce, and write a short migration note showing the dynamic import() fallback for CommonJS consumers on older runtimes.

As a consumer: if an ESM-only upgrade breaks your build, check first whether your runtime can now require it directly. If not, either load it with await import() at the boundary, or stay on the previous major until you can upgrade the runtime.

For the case where you still need both formats, read our position paper on dual packages.