Publishing TS Libraries for Fun and Profit - Mark Erikson, TypeScript Congress 2023

Discover the challenges and complexities of publishing TypeScript libraries, from ESM and CommonJS formats to maintaining backwards compatibility. Learn how the author found a solution with tsup and the evolving state of the ecosystem.

Key takeaways
  • Publishing a TypeScript library requires understanding the complexities of ESM, CommonJS, and UMD file formats, as well as the differences in how module systems work in browsers and Node.js.
  • The exports field in package.json is not well-supported, and tools like Webpack 4 and Rollup have their own expectations.
  • Recognizing the need for a more clear guide, the author wrote a blog post about their experiences and pain points in publishing TypeScript libraries.
  • The author’s research showed that adding type module and exports fields did not necessarily solve the problems.
  • Much of the ecosystem is still based on CommonJS and ESM, with many libraries using both file formats simultaneously.
  • Writing a fully-definitive guide on how to publish a package is a complex task.
  • The author has found tsup, a wrapper around esbuild, to be helpful in managing build artifacts and types.
  • There are many different tools and configurations being used, making it difficult to maintain backwards compatibility.
  • The author’s experiment with changing the package format from CommonJS to ESM revealed many unexpected issues.
  • The TypeScript team has been working on improving support for ESM, but the ecosystem is still in flux.
  • The author’s conclusion is that publishing a TypeScript library requires a deep understanding of the complexities involved and a willingness to adapt to changing technologies and tooling.