Skip to content

refactor: remove CommonJS build#609

Draft
wojtekmaj wants to merge 2 commits into
node-cron:mainfrom
wojtekmaj:remove-cjs-build
Draft

refactor: remove CommonJS build#609
wojtekmaj wants to merge 2 commits into
node-cron:mainfrom
wojtekmaj:remove-cjs-build

Conversation

@wojtekmaj

Copy link
Copy Markdown
Contributor

This is stacked on #608, so the diff currently includes that PR until it lands.

node-cron already requires Node 20+, and v5 is the right time to consider whether keeping a separate CommonJS build is still worth it. Node 20.19.0 enabled require(esm) by default, so CommonJS consumers on the supported runtime can load the same ESM entry instead of needing a second build artifact.

This removes the CJS build and points the package at the ESM output only:

"exports": {
  ".": {
    "types": "./dist/node-cron.d.ts",
    "module-sync": "./dist/node-cron.js",
    "default": "./dist/node-cron.js"
  }
}

To keep that technically accurate, the Node engine floor moves from >=20 to >=20.19.0, which is the Node 20 release where require(esm) stopped requiring --experimental-require-module. Reference: https://nodejs.org/en/blog/release/v20.19.0

The package-size impact is meaningful. Measured with npm pack --dry-run --json on clean temp copies:

#608 base
package size:   62,816 bytes
unpacked size: 327,517 bytes
entries:       17

this PR
package size:   37,396 bytes
unpacked size: 169,332 bytes
entries:       10

That is 25,420 fewer packed bytes (40.5% smaller) and 158,185 fewer unpacked bytes (48.3% smaller).

The deleted output is the duplicated CJS surface: node-cron.cjs, daemon.cjs, _shared.cjs, their sourcemaps, and the CJS-only declaration file from #608. It also removes the Rollup replace plugin that only existed to rewrite ESM-specific paths for the CJS build.

Checked with:

npm run build
npm run typecheck
npm run lint
npm test
npm pack --dry-run --json
npx @arethetypeswrong/cli --pack . --profile esm-only --format table --no-color

I also smoke-tested the packed package with both import styles on a Node runtime where process.features.require_module === true:

import cron, { schedule } from "node-cron";

const cron = require("node-cron");

And typed CommonJS consumption in TypeScript nodenext mode:

import cron = require("node-cron");

cron.schedule("* * * * *", () => {});

@wojtekmaj wojtekmaj changed the title refactor: Remove CommonJS build refactor: remove CommonJS build Jul 3, 2026
@merencia

merencia commented Jul 4, 2026

Copy link
Copy Markdown
Member

hey @wojtekmaj thanks for sharing that!

I need to think about this a bit more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants