Skip to content

Migrate to ESM #928

@ItsHarper

Description

@ItsHarper

As Babel explains in their blog post about Babel 8 beta, node.js 20 supports calling require() on ESM modules, so going esm-only shouldn't break any users on version 20+:

Babel 8 will ship as an ESM-only package. We've been trying to figure out how to make this work for very long time, and finally with the require(esm) support shipped in Node.js 20 we are comfortable with not providing a CommonJS alternative.

As someone with experience in this area, I can promise you it is far, far easier to maintain an ESM-only package. The slow death of CommonJS is truly something to celebrate. I tried fixing the failing test in #927 without migrating to ESM, and I could not figure out why I couldn't get built-in fetch working. Even if switching to ESM doesn't fix those problems directly, it will be a much more straightforward environment to debug (though honestly I do expect the issues I was having to go away with ESM).

#923 is already open, but it's incredibly heavy-handed, and I certainly do not fault you for not engaging with it. I wouldn't even know where to begin reviewing it.

I'm planning on submitting a series of PRs to do this, and I'll use this issue as a source of truth and discussion point for the steps to get there. That way each step can easily be reviewed. Even the final diff should be much, much smaller than #923 though (I truly do not know why it changes so many lines). I'm planning to do this work in a fork regardless of whether my PRs get merged or not.

  • Update to PNPM 10:
    • build: update pnpm #929
    • Currently, if you have PNPM 10 installed locally, it will just mostly-silently let you use it, but everything will break because the default settings changed.
  • Allow building all packages and running all tests with a single command
  • Update Typescript
    • chore: update typescript #931
    • Modern Typescript versions have better support for consolidating configuration files (see next step), and have options to support ESM in nicer ways.
  • Consolidate Typescript configuration
  • Update jest
    • This will fix access to the built-in fetch function from the tests, which will fix the test that fails on node 24.
  • Maybe another step or two? I've written down the stepping stones that came to mind, but I'm probably forgetting something. I'll update this issue as needed.
  • Migrate to ESM
  • Remove cross-fetch, bump minimum version in engines field to 18
  • Release with a bumped major version number

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions