ECMAScript modules
The standard JavaScript module system, written with import and export statements, used by browsers and modern tools.
In more detail
ESM stands for ECMAScript modules. Imports are static, so bundlers can see which exports are unused and remove them. Packages often ship ESM files with a .mjs extension alongside CommonJS for older consumers.
Example
import { useState } from "react";Related terms
- CommonJS — Node.js's original module system, which loads code with require() and exports it with module.exports.
- dual package — A package that ships both an ECMAScript module build and a CommonJS build, choosing between them through export conditions.
- tree shaking — Removing code that is exported but never imported from the final bundle, so less code is shipped.
- top-level await — Using await directly in the body of an ES module, outside any async function, so the module waits for a promise before it finishes loading.
- import.meta — An object available inside an ES module that describes the module itself; import.meta.url is the file:// URL of the current file.
- module resolution — How a runtime or tool turns the name in an import, such as ./util.js or express, into the exact file to load.
- dynamic import — The import() expression that loads a JavaScript module at run time and returns a promise for it.
- bundle — The files a build tool produces by combining an application's code and its libraries for the browser to download.
- ECMAScript — The official standard that defines the JavaScript language, updated every year by a committee of the Ecma International standards body.
- import and export — The statements that share code between modules: export makes a name available, import brings it into another file.
- NodeNext — A module and moduleResolution setting that makes TypeScript follow exactly the module rules of current Node.js.
- module (compiler option) — The compiler option that says which module system the output uses and, with NodeNext, how each file is treated.
Taught in
- Component Packaging: Dual ESM/CJS Builds & Package Exports — Design Systems & Component Engineering
- Native Module Systems: ESM Loader Hooks vs CommonJS — Node.js Internals & Backend Services
- Code-Splitting with React.lazy: Dynamic Imports And Chunks — React 19 & Modern Component Architecture
- tsconfig.json: target, lib, strict And NodeNext — Production TypeScript
- ECMAScript Modules, CJS Interop And verbatimModuleSyntax — Production TypeScript