ESM Loaders: Enhancing Module Loading in Node.js
summary
Explains how ESM loaders hook the module resolve/load hooks to change resolution and file reads, with concrete examples: an overrides.json resolver that rewrites specifiers, an HTTP loader that uses built-in fetch, and a TypeScript transformer using esbuild transpiler to return JS source. Shows chaining multiple loaders via --loader flags, implements cache-busting by appending gen=query to resolved URLs, and details Node 20+ changes (loader workers, message ports and SharedArrayBuffer+Atomics) needed to make API-driven features work — examples compile and run after those fixes.
AI-written summary · about
chapters (12)
- 0:00Introduction to ESM loaders
- 1:47What are ESM modules
- 4:36Module loaders overview
- 6:01Overriding module resolution
- 9:34Enhancing the loading phase
- 12:02Handling HTTP URLs in loaders
- 15:31Transpiling TypeScript with loaders
- 18:05Chaining multiple loaders
- 21:35Caching behavior in ESM
- 22:36Clearing module cache
- 25:22Loader communication in Node 20
- 28:41Summary and future of ESM loaders








