One module system for browsers, Node.js, Deno, and Bun. Learn import and export in ten minutes, then come back for the exact answer when a build, an import, or a migration breaks.
app.js imports what it needs and nothing leaks into the global scope.Browsers, Node.js, Deno, and Bun all run ES Modules natively.
The realistic floor. Node.js 20 reached end of life on 04-30-2026.
Stable in Node.js, so CommonJS code can load an ES Module directly.
Baseline: Chrome 89, Firefox 108, and Safari 16.4 resolve bare specifiers.
One file exports values. Another file imports them by name. That is the whole idea - everything else on this site is detail.
math.js - share it
export const add = (a, b) => a + b;
export default function square(n) {
return n * n;
}
app.js - use it
import square, { add } from './math.js';
console.log(add(2, 3)); // 5
console.log(square(4)); // 16
Run it in a browser
<script type="module" src="./app.js"></script>
Run it in Node.js
{ "type": "module" }
The browser line goes in your HTML. The Node.js line goes in package.json, then node app.js runs it. Next: every import and export form, or browser and Node.js setup in full.
The eight guides readers open most. Pick the question you are trying to answer today.
Vite, Rolldown, Rollup, webpack, Rspack, and Turbopack - and which one fits your project.
Pick a bundlerUse npm-style package names in the browser with no bundler and no build step.
Map a specifierTurn ES Modules on in a browser and in Node.js, and what differs between the two.
Set it upShort, direct answers on browsers, Node.js, TypeScript, tooling, and migration.
Find your questionNamed exports, default exports, namespace imports, and re-exports, with runnable code.
Learn the syntaxFrom script tags and IIFEs through CommonJS and AMD to one standard.
See how we got hereWhat Node.js, Deno, Bun, and browsers each support, and how to configure them.
Compare runtimesES Modules against CommonJS, AMD, and UMD, feature by feature.
See the tablesThree phases, always in this order. Knowing them explains most of the errors you will ever see.
The host starts at your entry file, finds every import, and fetches and parses each file it points to. Nothing runs yet. A wrong path, a missing extension, or a blocked request fails here.
Every export gets a slot in memory and every import is wired to the slot it names. These are live bindings, not copies. Asking for a name the module does not export fails here, before any code executes.
Module code runs once, dependencies first. Import the same file from ten places and it still executes a single time, so module-level state is shared by every importer.
Go deeper: how a specifier becomes a file, and live bindings, cycles, and top-level await.
The six messages that send most people looking. Each one links to its cause and the exact fix.
SyntaxError: Cannot use import statement outside a module
The file ran as a classic script or as CommonJS.
ERR_MODULE_NOT_FOUND
Usually a missing file extension or a wrong relative path.
ERR_REQUIRE_ESM
CommonJS code called require() on an ES Module on an older Node.js.
does not provide an export named ...
A named import that the module does not export, often a CommonJS package.
blocked by CORS policy
The page was opened from file:// or the other origin sent no CORS header.
Expected a JavaScript module script
The server answered with the wrong MIME type, often an HTML 404 page.
Every page on the site, grouped into five tracks. Start with Core if you are new, jump to Practices when something is broken, or use Reference to look up a specific answer.
The syntax, the mental model, and how ES Modules relate to what came before.
Master import and export statements, named exports, default exports, and namespace imports.
Learn how ES Modules work in both browser and Node.js environments.
Dynamic imports, top-level await, circular dependencies, and live bindings.
Mix require and import safely: require(esm), createRequire, named export detection, and the dual package hazard.
Compare ES Modules vs CommonJS, bundlers, browser support, and module formats.
Quick reference guide for import/export syntax with printable format.
How a specifier becomes a file, and how to configure the tools that decide.
Understand how modules are resolved, specifiers, and the module algorithm.
Control module resolution in the browser with import maps for bare specifiers and CDN packages.
Use import attributes to load JSON, CSS, and other non-JavaScript modules safely.
The full reference for import.meta.url, resolve, dirname, filename, and main.
Node.js module customization with register(), plus the resolve and load hooks that replaced loaders.
Configure TypeScript for native ES Modules with tsconfig settings, path mapping, and declaration files.
Bundlers, transpilers, testing frameworks, and development tools for ES Modules.
Where ES Modules actually run, and what each platform supports today.
ES Modules across Node.js, Deno, Bun, and browser runtimes with configuration guides.
How React, Vue, Svelte, Angular, and Next.js leverage ES Modules under the hood.
Test ES Modules with Vitest, Jest, and the Node.js test runner using modern mocking and assertions.
Publish ESM-only and dual packages to npm with proper exports, types, and package.json configuration.
Use ES Modules in Web Workers, Service Workers, and Shared Workers for parallel processing.
Load and integrate WebAssembly modules using ES Module imports for high-performance code.
One maintained matrix for every ES Modules feature across browsers, Node.js, Deno, and Bun.
Track import defer, source phase imports, import text, and the rest of module harmony.
Getting it right, making it fast, and fixing it when it breaks.
The opinionated do and do-not list for module layout, exports, and dependency boundaries.
Singletons, dependency injection, plugin systems, and environment-based loading.
Optimize module loading, preloading, and Core Web Vitals impact.
What the sideEffects field really does, why barrel files defeat it, and how to verify.
Debug module issues, read stack traces, and troubleshoot common problems.
Every ES Modules error message, what causes it, and the exact fix. Paste your error and find it here.
Integrity, auditing, provenance, and supply-chain defense for module graphs.
Step-by-step guide to migrate a CommonJS codebase to ES Modules.
Real migrations with before and after code: a library going ESM-only, a monorepo, and a build-free app.
Look something up, copy something out, or check a definition.
Practical implementations including routers, API clients, and real applications.
Practice what you have read. Hands-on exercises with solutions, plus a self-scoring quiz.
Micro-frontends, design systems, plugin architectures, edge functions, and no-build apps.
Ready-to-use configuration files: package.json, tsconfig, vite.config, and more.
Paste a package.json and check its exports map, condition order, and types wiring in your browser.
Definitions of key ES Modules terms from bare specifiers to tree-shaking and live bindings.
Answers to frequently asked questions about ES Modules, compatibility, and best practices.
Trace the evolution of JavaScript modules from script tags to ES Modules and beyond.
Official specifications, documentation, tools, learning resources, and community links.
What changed on the site and what changed in the ES Modules ecosystem, newest first.
Don't just read about ES Modules - run real code in your browser.
Each example is a real set of module files loaded by your browser's own module loader, with the console output captured next to the code. Change an import, break an export on purpose, and watch which of the three loading phases reports it.
Run real ES Module code directly in your browser. See console output, test different imports, and learn interactively.
Every example includes a one-click export to CodePen. Experiment freely, modify code, and see results instantly.
No simulations! Actual ES Modules running in isolated iframes with real browser behavior and console output.
JavaScript has evolved. The days of global namespace pollution, complex bundler configurations, and competing module formats are giving way to a standardized, powerful, and native solution: ES Modules. This is the future of writing clean, reusable, and performant code for the web, and ESModules.com is your definitive resource for mastering it.
Our mission is to accelerate the awareness and adoption of this critical technology. We believe that a deep understanding of ES Modules is no longer optional - it's a foundational skill for modern developers committed to continuous learning and building for the long term.
This site isn't just a collection of documentation; it's a living project built from real-world experience. The team at RJL.dev - a group of practicing software engineers and architects - created and actively maintains every piece of content you'll find here. We've navigated the challenges, debugged the tricky edge cases, and optimized the patterns so you can learn from our expertise.
Because we are in the trenches coding every day, we stand behind our content with confidence. We are committed to providing you with:
Clear, step-by-step guides that take you from foundational concepts to advanced techniques.
Go beyond the syntax to learn the patterns and strategies for writing truly maintainable and scalable modular code.
Real-world, copy-paste-ready snippets that solve common problems and illustrate key principles.
Learn how to diagnose and fix module resolution errors, circular dependencies, and other common pitfalls.
A handpicked collection of the best tools, articles, and documentation from around the web to supplement your learning.
ESModules.com is more than a website; it's our commitment to elevating the JavaScript community. We invite you to dive in, explore the resources, and join us in building the future of the web - one module at a time.
Quick answers to the ES Modules questions we hear most. Need more? The full FAQ answers 33 of them, grouped by error message, browser, Node.js, TypeScript, tooling, and migration.
Found a mistake, a stale version number, or a question this site does not answer? Tell us.