# Building an npm package compatible with ESM and CJS in 2024

DevFeed: [Building an npm package compatible with ESM and CJS in 2024](<https://devfeed.tech/articles/building-an-npm-package-compatible-with-esm-and-cjs-in-2024-7854.md>)

Original publisher: [Read original article](<https://snyk.io/blog/building-npm-package-compatible-with-esm-and-cjs-2024/>)

Author: Liran Tal

Published: 2024-04-18T17:00:00Z

Content type: article

Language: en

Sources: [Blog RSS Feed | Snyk](<https://devfeed.tech/sources/blog-rss-feed-snyk.md>)

Topics: [npm](<https://devfeed.tech/topics/npm.md>), [ECMAScript](<https://devfeed.tech/topics/ecmascript.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>), [Node.js](<https://devfeed.tech/topics/node-js.md>), [Code](<https://devfeed.tech/topics/code.md>), [Open Source](<https://devfeed.tech/topics/open-source.md>)

Tags: [awareness](<https://devfeed.tech/tags/awareness.md>), [best-practices](<https://devfeed.tech/tags/best-practices.md>), [blog](<https://devfeed.tech/tags/blog.md>), [commonjs](<https://devfeed.tech/tags/commonjs.md>), [developer](<https://devfeed.tech/tags/developer.md>), [devrel](<https://devfeed.tech/tags/devrel.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [github](<https://devfeed.tech/tags/github.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [javascript-packages](<https://devfeed.tech/tags/javascript-packages.md>), [node-js](<https://devfeed.tech/tags/node-js.md>), [npm](<https://devfeed.tech/tags/npm.md>), [open-source](<https://devfeed.tech/tags/open-source.md>), [open-source-security](<https://devfeed.tech/tags/open-source-security.md>), [snyk-open-source](<https://devfeed.tech/tags/snyk-open-source.md>), [typescript](<https://devfeed.tech/tags/typescript.md>)

## AI overview

This article explains how to publish npm packages that support both ECMAScript Modules (ESM) and CommonJS (CJS). It discusses package manifest fields, entry-point resolution, TypeScript integration, and practical compatibility considerations, with code examples and a referenced GitHub repository.

## Source excerpt

Publishing JavaScript packages that are compatible with both ECMAScript Modules (ESM) and CommonJS (CJS) is a critical skill for developers who aim to integrate wide-ranging libraries. This write-up focuses on practical approaches and best practices for maintaining ESM and CJS support.