Skip to content

feat: implement true ESM#479

Open
wojtekmaj wants to merge 1 commit into
node-cron:mainfrom
wojtekmaj:esm
Open

feat: implement true ESM#479
wojtekmaj wants to merge 1 commit into
node-cron:mainfrom
wojtekmaj:esm

Conversation

@wojtekmaj
Copy link
Copy Markdown

@wojtekmaj wojtekmaj commented Aug 7, 2025

Efforts were made to introduce ESM builds in node-cron. However, they were not fully completed.

What was done

  • Enabled easier local testing with arethetypeswrong
    • Added *.tgz to .gitignore to ignore the file that npm pack outputs
    • Changed prepublishOnly to prepack to build the package before packing it - not necessarily with the intention of immediately publishing it
  • Rewrote all import paths to actually be ESM compatible (/some-module.js -> ./some-module.js, ./some-directory -> ./some-directory/index.js)
  • Build changes
    • Rewrote type, types, exports fields in package.json
    • Reworked build commands to add a secondary package.json in /dist/cjs guiding Node.js module resolution algorithm
  • TypeScript changes
    • simplified setup: default TypeScript config is now ESM, CJS config inherits from it and has CJS-specific overrides
    • verbatimModuleSyntax setting was enabled to prevent TypeScript from creating empty modules, like dist/esm/tasks/scheduled-task.js:
      image

What still needs attention

  • Path resolving in startDaemon
  • Dual testing on built code: CJS and ESM

Before

/dist/esm still contains code compiled to CJS:

image

https://www.npmjs.com/package/node-cron?activeTab=code

and arethetypeswrong reports CJS default export on ESM environments:

image

https://arethetypeswrong.github.io/?p=node-cron%404.2.1

After

/dist/esm contains ESM code:

image

and arethetypeswrong CLI reports no issues with module resolution:

image

Efforts were made to introduce ESM builds in node-cron. Unfortunately, they were not fully completed: /dist/esm still contains code compiled to CJS and [arethetypeswrong](https://arethetypeswrong.github.io/) reports CJS default export on ESM environments.
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.

1 participant