ESM vs. CJS: Navigating JavaScript's Module Divide
JavaScript has two module systems: modern, static ESM (`import`) and legacy, dynamic CJS (`require`). When publishing a library, you must support both. The footgun is shipping only ESM, as it breaks downstream projects that still use `require()`.
JavaScript has two incompatible module systems: modern, static ESM (`import`) and legacy, dynamic CommonJS (`require`). This is critical for library authors whose packages must work in modern bundlers (Vite) and older Node setups (Jest). The main footgun is publishing only an ESM package; CJS projects cannot `require()` it, causing build failures. Providing both formats is the safest path.
Read the original → nodejs.org
- #javascript
- #modules
- #nodejs
- #npm
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.