Tutorial: publishing ESM-based npm packages with TypeScript
12-Feb-2025 11
During the last two years, ESM support in TypeScript, Node.js and browsers has made a lot of progress. In this blog post, I explain my modern setup that is relatively simple – compared to what we had to do in the past:
It is intended for packages that can afford to ignore backward compatibility. The setup has worked well for me for a while – since TypeScript 4.7 (2022-05-24).
It helps that Node.js now supports “require(esm)” – requiring ESM libraries from CommonJS modules.
I’m only using tsc, but mention how to support other tools via tsconfig.json in section “Compiling TypeScript with tools other than tsc”.
Feedback welcome: What do you do differently? What can be improved?
Example package: @rauschma/helpers uses the setup described in this blog post.
Tutorial: publishing ESM-based npm packages with TypeScript #js #javascript #Tutorial: #publishing #ESM-based #packages #TypeScript #tutorial: #typescript https://javascript.ba/link/tutorial-publishing-esm-based-npm-packages-with-typescript