<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Esm on Ghafoor's Personal Blog</title><link>https://ghafoorsblog.com/tags/esm/</link><description>Recent content in Esm on Ghafoor's Personal Blog</description><generator>Hugo</generator><language>en</language><managingEditor>hello@ghafoorsblog.com (AG Sayyed)</managingEditor><webMaster>hello@ghafoorsblog.com (AG Sayyed)</webMaster><copyright>Copyright © 2024-2026 AG Sayyed. All Rights Reserved.</copyright><lastBuildDate>Sun, 24 May 2026 09:13:13 +0100</lastBuildDate><atom:link href="https://ghafoorsblog.com/tags/esm/index.xml" rel="self" type="application/rss+xml"/><item><title>JavaScript Modules — ES Modules, CommonJS, and the Modern Module Ecosystem</title><link>https://ghafoorsblog.com/posts/js/08-modules/</link><pubDate>Mon, 15 Sep 2025 08:00:00 +0000</pubDate><author>hello@ghafoorsblog.com (AG Sayyed)</author><guid>https://ghafoorsblog.com/posts/js/08-modules/</guid><description>&lt;h2 id="the-problem-a-module-system-solves"&gt;The problem a module system solves&lt;/h2&gt;
&lt;p&gt;For most of its history JavaScript had &lt;strong&gt;no&lt;/strong&gt; module system. Every script shared one global namespace. The solutions were progressively cleverer hacks:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;IIFE&lt;/strong&gt; — an immediately-invoked function expression wrapping the code in a private scope, exposing a single global.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Module Pattern&lt;/strong&gt; — &lt;code&gt;var MyLib = (function () { ... })()&lt;/code&gt; — closures emulating private members.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;AMD&lt;/strong&gt; (RequireJS) — asynchronous loading designed for the browser.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CommonJS&lt;/strong&gt; — synchronous &lt;code&gt;require()&lt;/code&gt; born inside Node.js, became the npm standard.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;UMD&lt;/strong&gt; — a wrapper that detects whether AMD, CommonJS, or a bare global is in scope and adapts.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In 2015 the language finally added &lt;strong&gt;ES Modules (ESM)&lt;/strong&gt; — a standard, statically analysable, asynchronous module system that works in both browsers and Node.&lt;/p&gt;</description></item></channel></rss>